add createOrUpdate for recipes

This commit is contained in:
Anika Raemer 2025-10-10 18:04:59 +02:00
parent 7252b072bd
commit 58ef7fbc00
4 changed files with 54 additions and 0 deletions

View file

@ -26,6 +26,7 @@ const recipeController = new RecipeHandler(recipeRepository, recipeMapper);
* Create new recipe
* Consumes: RecipeDto
* Responds with RecipeDto
* DEPRECATED!
*/
router.post(
"/",
@ -36,6 +37,23 @@ router.post(
})
);
/**
* Save or update recipe.
* Consumes: RecipeDto
* Responds with RecipeDto as saved in database
* A new recipe is created if the dto doesn't contain an ID. Otherwise, the
* existing recipe is updated. Throws an exception if the dto does contain an
* ID that's not present in the database
*/
router.post(
"/create-or-update",
asyncHandler(async(req, res) => {
const requestDto: RecipeDto = req.body;
const responseDto = await recipeController.createOrUpdateRecipe(requestDto);
res.status(201).json(responseDto);
})
)
/**
* Load recipe by id
* Responds with RecipeDto
@ -54,6 +72,7 @@ router.get(
* Also handles changes to instructions steps and ingredient (groups)
* Consumes: RecipeDto
* Responds with RecipeDto
* DEPRECATED
*/
router.put(
"/:id",