diff --git a/backend/src/controllers/userControllers.js b/backend/src/controllers/userControllers.js index 2a0b35c..52cc8e2 100644 --- a/backend/src/controllers/userControllers.js +++ b/backend/src/controllers/userControllers.js @@ -40,7 +40,7 @@ const edit = async (req, res, next) => { const wantedId = parseInt(req.params.id, 10); // Extract the user data from the request body const item = req.body; - item.ID = wantedId; + item.id = wantedId; const avatar = req.file; fs.renameSync( `${avatar.destination}/${avatar.filename}`, @@ -48,7 +48,6 @@ const edit = async (req, res, next) => { ); const newpath = `${avatar.destination}/${avatar.filename}-${avatar.originalname}`; - console.info({ item, avatar }); try { // Insert the recipe into the database const user = await tables.user.update(item, newpath); diff --git a/backend/src/models/UserManager.js b/backend/src/models/UserManager.js index 256a275..d6a9d30 100644 --- a/backend/src/models/UserManager.js +++ b/backend/src/models/UserManager.js @@ -68,8 +68,15 @@ class UserManager extends AbstractManager { // Execute the SQL SELECT query to retrieve a specific user by its Username const [result] = await this.database.query( `UPDATE ${this.table} SET firstname = ?, lastname = ?, birthdate = ?, description = ?, avatar = ? -WHERE username = ?`, - [user.firstname, user.lastname, user.birthdate, user.description, avatar] +WHERE user.id = ?`, + [ + user.firstname, + user.lastname, + user.birthdate, + user.description, + avatar, + user.id, + ] ); // Return the first row of the result, which represents the user diff --git a/backend/src/router.js b/backend/src/router.js index 6c56897..bbc50a4 100644 --- a/backend/src/router.js +++ b/backend/src/router.js @@ -30,14 +30,13 @@ router.get("/verify-token", AuthControllers.verifyToken); router.use(AuthMiddleware.verifyToken); -router.get("/users", UserControllers.browse); // Route to get a list of items -router.get("/users/:id", UserControllers.read); // Route to get a specific item by ID - router.put( "/users/:id", uploadUsersAvatars.single("avatar"), UserControllers.edit ); +router.get("/users", UserControllers.browse); // Route to get a list of items +router.get("/users/:id", UserControllers.read); // Route to get a specific item by ID // Route to update user router.post( diff --git a/frontend/src/components/Step1.jsx b/frontend/src/components/Step1.jsx index ec11233..9eed819 100644 --- a/frontend/src/components/Step1.jsx +++ b/frontend/src/components/Step1.jsx @@ -15,15 +15,15 @@ function Step1({ tag }) { const difficulties = [ { - value: "easy", + value: "Facile", label: "Facile", }, { - value: "medium", + value: "Moyen", label: "Moyen", }, { - value: "hard", + value: "Difficile", label: "Difficile", }, ]; diff --git a/frontend/src/components/Step2.jsx b/frontend/src/components/Step2.jsx index d4b1df0..498f608 100644 --- a/frontend/src/components/Step2.jsx +++ b/frontend/src/components/Step2.jsx @@ -15,6 +15,7 @@ export default function Step2({ ingredient }) { const [unit, setUnit] = React.useState(""); const handleAddIngredient = () => { const ingredientToAdd = { + id: ingredientList.length, name: ingredientName, quantity, unit, @@ -28,6 +29,11 @@ export default function Step2({ ingredient }) { setUnit(""); }; + const handleDeleteIngredient = (id) => { + setIngredientList(ingredientList.filter((object) => object.id !== id)); + }; + + console.info(ingredientList); const combineHandler = async () => { handleReset(); await handleAddIngredient(); @@ -80,7 +86,12 @@ export default function Step2({ ingredient }) { {item.name} {item.quantity} {item.unit} - + ))} diff --git a/frontend/src/components/Step3.jsx b/frontend/src/components/Step3.jsx index 631ae45..ada91e0 100644 --- a/frontend/src/components/Step3.jsx +++ b/frontend/src/components/Step3.jsx @@ -11,6 +11,7 @@ export default function Step3() { const [description, setDescription] = React.useState(""); const handleAddingInstruction = () => { const instructionToAdd = { + id: instructionList.length, name: description, }; setAddInstruction((prev) => [...prev, instructionToAdd]); @@ -20,6 +21,12 @@ export default function Step3() { setDescription(""); }; + const handleDeleteInstruction = (id) => { + setInstructionList( + instructionList.filter((instruction) => instruction.id !== id) + ); + }; + const combineHandler = async () => { handleReset(); await handleAddingInstruction(); @@ -50,7 +57,12 @@ export default function Step3() { {instructionList.map((item) => (
{item.name} - +
))} diff --git a/frontend/src/components/Step4.jsx b/frontend/src/components/Step4.jsx index d2e8095..a985218 100644 --- a/frontend/src/components/Step4.jsx +++ b/frontend/src/components/Step4.jsx @@ -1,4 +1,5 @@ import axios from "axios"; +import React from "react"; import { useIngredientCreation } from "../contexts/IngredientCreationContext"; import { useInstructionCreation } from "../contexts/InstructionCreationContext"; import { useRecipeCreation } from "../contexts/RecipeCreationContext"; @@ -21,32 +22,57 @@ function Step4() { difficulty, } = recipeCreation; - const Post = () => { - axios - .post( - `${import.meta.env.VITE_BACKEND_URL}/api/recipes`, - { - name: recipeName, - title: recipeDesc, - prep_time: prepTime, - nb_people: nbPeople, - tag1, - tag2, - tag3, - difficulty, - }, - { - withCredentials: true, - } - ) - .then((res) => res.status(201)) - .catch((err) => console.error(err)); + const handlePost = async () => { + try { + const response = await axios + .post( + `${import.meta.env.VITE_BACKEND_URL}/api/recipes`, + { + name: recipeCreation.recipeName, + title: recipeCreation.recipeDesc, + prep_time: recipeCreation.prepTime, + nb_people: recipeCreation.nbPeople, + difficulty: recipeCreation.difficulty, + tag1: recipeCreation.tag1, + tag2: recipeCreation.tag2, + tag3: recipeCreation.tag3, + }, + { + withCredentials: true, + } + ) + .then(() => console.info(response)); + } catch (error) { + console.error(error); + } }; - return (

Step 4

-
diff --git a/frontend/src/pages/CreateRecipe.jsx b/frontend/src/pages/CreateRecipe.jsx index d322d4e..9cb7b41 100644 --- a/frontend/src/pages/CreateRecipe.jsx +++ b/frontend/src/pages/CreateRecipe.jsx @@ -15,7 +15,7 @@ import Step4 from "../components/Step4"; const steps = [ "Nom, photo et description", - "Ingrédients et matériel", + "Ingrédients", "Instructions", "Confirmation", ]; @@ -103,7 +103,7 @@ export default function CreateRecipe() { {activeStep === steps.length - 1 ? ( - + "" ) : ( )}