save recipes
This commit is contained in:
parent
3a887d8dbb
commit
380eb4cd21
18 changed files with 412 additions and 87 deletions
|
|
@ -3,6 +3,10 @@ import { RecipeRepository } from "../repositories/RecipeRepository.js";
|
|||
import { RecipeDtoEntityMapper } from "../mappers/RecipeDtoEntityMapper.js";
|
||||
import { RecipeController } from "../controllers/RecipeController.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import { RecipeDto } from "../dtos/RecipeDto.js";
|
||||
import { RecipeIngredientDtoEntityMapper } from "../mappers/RecipeIngredientDtoEntityMapper.js";
|
||||
import { RecipeIngredientGroupDtoEntityMapper } from "../mappers/RecipeIngredientGroupDtoEntityMapper.js";
|
||||
import { RecipeInstructionStepDtoEntityMapper } from "../mappers/RecipeInstructionStepDtoEntityMapper.js";
|
||||
|
||||
/**
|
||||
* Handles all user related routes
|
||||
|
|
@ -11,16 +15,34 @@ const router = Router();
|
|||
|
||||
// Inject repo + mapper here
|
||||
const recipeRepository = new RecipeRepository();
|
||||
const recipeDtoEntityMapper = new RecipeDtoEntityMapper();
|
||||
const recipeController = new RecipeController(recipeRepository, recipeDtoEntityMapper);
|
||||
const recipeIngredientMapper = new RecipeIngredientDtoEntityMapper();
|
||||
const recipeIngredientGroupMapper = new RecipeIngredientGroupDtoEntityMapper(recipeIngredientMapper);
|
||||
const recipeInstructionStepMapper = new RecipeInstructionStepDtoEntityMapper();
|
||||
const recipeMapper = new RecipeDtoEntityMapper(recipeInstructionStepMapper, recipeIngredientGroupMapper);
|
||||
const recipeController = new RecipeController(recipeRepository, recipeMapper);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* Create new recipe
|
||||
*/
|
||||
router.post(
|
||||
"/",
|
||||
asyncHandler(async (req, res) => {
|
||||
const requestDto : RecipeDto = req.body;
|
||||
const responseDto = await recipeController.createRecipe(requestDto);
|
||||
res.status(201).json(responseDto);
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Load all recipes
|
||||
*/
|
||||
router.get(
|
||||
"/",
|
||||
asyncHandler(async (req, res) => {
|
||||
asyncHandler(async (req, res) => {
|
||||
const response = await recipeController.getAllRecipes();
|
||||
res.status(201).json(response);
|
||||
})
|
||||
);
|
||||
);
|
||||
|
||||
export default router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue