update interface detail recipe

This commit is contained in:
bastien ollier
2024-06-17 15:21:00 +02:00
committed by clfreville2
parent e87e754f92
commit 86a1dbb3e3
5 changed files with 91 additions and 33 deletions

View File

@@ -1,12 +1,15 @@
import { Injectable } from '@angular/core';
import { Recipe } from '../cookbook/type';
import { Ingredient, Recipe } from '../cookbook/type';
@Injectable({
providedIn: 'root',
})
export class RecipeService {
#recipes: Recipe[] = [
{ id: 0, name: 'crepe1', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
{ id: 0, name: 'crepe1', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [
{idIngredient:1,idRecipe:0,quantity:10},
{idIngredient:2,idRecipe:0,quantity:15}
] },
{ id: 1, name: 'crepe2', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
{ id: 2, name: 'crepe3', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
{ id: 3, name: 'crepe4', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
@@ -22,14 +25,27 @@ export class RecipeService {
{ id: 13, name: 'crepe14', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
];
#ingredients: Ingredient[] = [
{ id:1, name:'Sucre'},
{ id:2, name:'Farine'}
]
getAll(): Recipe[] {
return this.#recipes;
}
getAllIngredients(): Ingredient[] {
return this.#ingredients;
}
get(id: number): Recipe | null {
return this.#recipes.find((recipe) => recipe.id === id) || null;
}
getIngredientById(id: number): Ingredient | null {
return this.#ingredients.find((ingredient) => ingredient.id === id) || null;
}
add(recipe: Omit<Recipe, 'id'>): void {
const id = this.#recipes.length ? Math.max(...this.#recipes.map((recipe) => recipe.id)) + 1 : 1;
this.#recipes.push({