-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/recipes #35
Open
StudioAzur
wants to merge
4
commits into
dev
Choose a base branch
from
feature/recipes
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/recipes #35
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f2029a6
feat(controller) mise en place du service pour la prtie backend des r…
StudioAzur 64b5ea2
feat(router)création du router pour les recettes :sparkles:
StudioAzur a88d719
fix(router) fix du router des recettes :adhesive_bandage:
StudioAzur 72be588
Merge branch 'dev' into feature/recipes
CindyGraffin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { recipeService } from './../service/recipeService'; | ||
|
||
|
||
export class RecipeController{ | ||
|
||
private service = recipeService; | ||
createRecipe = async (req: Request, res: Response, next: NextFunction): Promise<void> => { | ||
try { | ||
const newRecipe = await this.service.addRecipe(req.body); | ||
res.status(200).json(newRecipe) | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
|
||
getRecipeById = async(req: Request, res: Response, next: NextFunction): Promise<void> => { | ||
try { | ||
const recipe = await this.service.getRecipe(req.params.id); | ||
res.status(200).json(recipe) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
getAllRecipes = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const users = await this.service.getAllRecipes(); | ||
res.status(200).json(users); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import mongoose from "mongoose"; | ||
import { Dto } from "./dto"; | ||
|
||
type Ingredients = { | ||
quantity: number; | ||
denomination: string | ||
} | ||
|
||
|
||
export interface RecipesDto extends Dto{ | ||
_id: mongoose.Schema.Types.ObjectId; | ||
title: string; | ||
times: number; | ||
difficulty: string | ||
ingredients: Ingredients[] | ||
instruction: string[] | ||
datePublication: Date | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import mongoose, { Schema } from "mongoose"; | ||
import { RecipesDto } from "../dtos/recipes.dto"; | ||
|
||
const RecipesSchema = new mongoose.Schema<RecipesDto>( | ||
{ | ||
title: { type: String, required: true }, | ||
times: { type: Number, required: true }, | ||
difficulty: { type: String, required: true }, | ||
ingredients: { | ||
quantity: { type: Number }, | ||
denomination: { type: String, required: true }, | ||
}, | ||
instruction: { type: [String], required: true }, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
const RecipesModel = mongoose.model<RecipesDto>("Recipes", RecipesSchema); | ||
export { RecipesModel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import express from "express";import { RecipeController } from "../controllers/recipes"; | ||
; | ||
|
||
const recipeController = new RecipeController(); | ||
const recipeRouter = express.Router(); | ||
|
||
recipeRouter.post('/createrecipe', recipeController.createRecipe) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pas besoin de la route 'createrecipe', juste '/' devrait suffire étant donné que le terme 'post' parle de lui -même |
||
recipeRouter.get('/:id', recipeController.getRecipeById) | ||
recipeRouter.get('/', recipeController.getAllRecipes) | ||
|
||
export {recipeRouter} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { RecipesModel } from "../models/RecipesModel"; | ||
import { RecipesDto } from "../dtos/recipes.dto"; | ||
|
||
export class RecipeService { | ||
addRecipe = async (recipe: RecipesDto): Promise<RecipesDto> => { | ||
const newRecipe = new RecipesModel(recipe); | ||
await newRecipe.save(); | ||
return newRecipe; | ||
}; | ||
|
||
getAllRecipes = async (): Promise<RecipesDto[]> => { | ||
const recipes = RecipesModel.find(); | ||
return recipes; | ||
}; | ||
|
||
getRecipe = async (id: string): Promise<RecipesDto> => { | ||
const recipe = await RecipesModel.findById(id).orFail(); | ||
return recipe; | ||
}; | ||
|
||
deleteRecipeById = async (recipeId: string): Promise<void> => { | ||
StudioAzur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await RecipesModel.deleteOne({ | ||
recipeId: recipeId, | ||
}); | ||
}; | ||
} | ||
export const recipeService = Object.freeze(new RecipeService()); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu as juste oublié de mettre en required la qauntité des ingrédients. si cela est facultatif ignore mon commentaire