diff --git a/backend/src/controllers/products.ts b/backend/src/controllers/products.ts index 3c00ae0..4d200a9 100644 --- a/backend/src/controllers/products.ts +++ b/backend/src/controllers/products.ts @@ -69,12 +69,12 @@ export const addProduct = [ upload, async (req: AuthenticatedRequest, res: Response) => { try { - const { name, price, description } = req.body; + const { name, price, description, year, category, condition} = req.body; if (!req.user) return res.status(404).json({ message: "User not found" }); const userId = req.user._id; const userEmail = req.user.userEmail; - if (!name || !price || !userEmail) { - return res.status(400).json({ message: "Name, price, and userEmail are required." }); + if (!name || !price || !userEmail || !year || !category || !condition) { + return res.status(400).json({ message: "Name, price, userEmail, year, category, condition, are required." }); } const images: string[] = []; @@ -101,6 +101,9 @@ export const addProduct = [ description, userEmail, images, + year, + category, + condition, timeCreated: new Date(), timeUpdated: new Date(), }); @@ -189,6 +192,9 @@ export const updateProductById = [ name: req.body.name, price: req.body.price, description: req.body.description, + year: req.body.year, + category: req.body.category, + condition: req.body.condition, images: finalImages, timeUpdated: new Date(), }, diff --git a/backend/src/models/product.ts b/backend/src/models/product.ts index ca7386a..973f962 100644 --- a/backend/src/models/product.ts +++ b/backend/src/models/product.ts @@ -12,6 +12,18 @@ const productSchema = new Schema({ description: { type: String, }, + year: { + type: Number, + required: true, + }, + category: { + type: String, + required: true, + }, + condition: { + type: String, + required: true, + }, timeCreated: { type: Date, required: true, diff --git a/frontend/src/components/Product.tsx b/frontend/src/components/Product.tsx index 4a5b4b5..a7b6bc2 100644 --- a/frontend/src/components/Product.tsx +++ b/frontend/src/components/Product.tsx @@ -10,6 +10,10 @@ interface Props { productImages: string[]; productName: string; productPrice: number; + productYear: number; + productCategory: string; + productCondition: string; + productLocation: string; isSaved?: boolean; onSaveToggle?: (productId: string, newSavedStatus: boolean) => void; } diff --git a/frontend/src/pages/AddProduct.tsx b/frontend/src/pages/AddProduct.tsx index bf68a9b..d100713 100644 --- a/frontend/src/pages/AddProduct.tsx +++ b/frontend/src/pages/AddProduct.tsx @@ -10,8 +10,26 @@ export function AddProduct() { const productName = useRef(null); const productPrice = useRef(null); const productDescription = useRef(null); + const productYear = useRef(null); + const productCategory = useRef(null); + const productCondition = useRef(null); const productImages = useRef(null); + + const currentYear = new Date().getFullYear(); + const years = Array.from({ length: currentYear - 1950 }, (_, i) => currentYear - i); + + + const categories = [ + 'Electronics', + 'School Supplies', + 'Dorm Essentials', + 'Furniture', + 'Clothes', + 'Miscellaneous']; + + const conditions = ["New", "Used"]; + const { user } = useContext(FirebaseContext); const [error, setError] = useState(false); const [fileError, setFileError] = useState(null); @@ -56,7 +74,7 @@ export function AddProduct() { setIsSubmitting(true); e.preventDefault(); try { - if (productName.current && productPrice.current && productDescription.current && user) { + if (productName.current && productPrice.current && productDescription.current && productYear.current && productCategory.current && productCondition.current && user) { let images; if (productImages.current && productImages.current.files) { images = productImages.current.files[0]; @@ -66,6 +84,9 @@ export function AddProduct() { body.append("name", productName.current.value); body.append("price", productPrice.current.value); body.append("description", productDescription.current.value); + body.append("year", productYear.current.value); + body.append("category", productCategory.current.value); + body.append("condition", productCondition.current.value); if (user.email) body.append("userEmail", user.email); if (productImages.current && productImages.current.files) { @@ -92,118 +113,215 @@ export function AddProduct() { Low-Price Center Marketplace -
+

Add Product

-
- {/* Name */} -
- - -
+ +
+
+ {/* Images */} +
+ +

Upload up to 10 photos

- {/* Price */} -
- - -
+ {newPreviews.length > 0 && ( +
+
+ {newPreviews.map((src, idx) => ( +
+ + +
+ ))} +
+
+ )} - {/* Description */} -
- -