add on models recipe and steps. Add on Services function for recipes. binding on page ingredientSelection and recipesDetails are done
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
1c665225b6
commit
3c6a2c2c6d
@ -0,0 +1,27 @@
|
|||||||
|
export default class Profil {
|
||||||
|
private _id: number;
|
||||||
|
private _name: string;
|
||||||
|
private _allergy: string[];
|
||||||
|
private _diets: string[];
|
||||||
|
|
||||||
|
constructor(id: number, name: string) {
|
||||||
|
this._id = id;
|
||||||
|
this._name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get id(): number{
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get allergy(): string[]{
|
||||||
|
return this._allergy;
|
||||||
|
}
|
||||||
|
|
||||||
|
get diets(): string[]{
|
||||||
|
return this._diets;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
import Ingredient from "./Ingredient";
|
||||||
|
|
||||||
|
export default class Recipes {
|
||||||
|
private _id: number;
|
||||||
|
private _name: string;
|
||||||
|
private _description: string;
|
||||||
|
private _time_to_cook: number;
|
||||||
|
private _steps: string[];
|
||||||
|
private _ingredients: Ingredient[];
|
||||||
|
|
||||||
|
constructor(id: number, name: string, description: string, time_to_cook: number, steps: string[], ingredients: Ingredient[]) {
|
||||||
|
this._id = id;
|
||||||
|
this._name = name;
|
||||||
|
this._description = description;
|
||||||
|
this._time_to_cook = time_to_cook;
|
||||||
|
this._steps = steps;
|
||||||
|
this._ingredients = ingredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get id(): number{
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get description(): string{
|
||||||
|
return this._description;
|
||||||
|
}
|
||||||
|
|
||||||
|
get time_to_cook(): number{
|
||||||
|
return this._time_to_cook;
|
||||||
|
}
|
||||||
|
|
||||||
|
get steps(): string[]{
|
||||||
|
return this._steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
get ingredients(): Ingredient[]{
|
||||||
|
return this._ingredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static convertApiResponse(apiResponse: string): Recipes[] {
|
||||||
|
const parsedResponses = JSON.parse(apiResponse);
|
||||||
|
return parsedResponses.map((item: any) => new Recipes(item.id, item.name, item.description, item.time_to_cook, item.steps, item.ingredient));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import Recipes from "../../Models/Recipes";
|
||||||
|
|
||||||
|
export default interface IRecipesService {
|
||||||
|
getAllRecipes(): Promise<Recipes[]>;
|
||||||
|
getRecipeById(id: Number): Promise<Recipes | null>;
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import IRecipesService from "./IRecipesServices";
|
||||||
|
import Recipes from "../../Models/Recipes";
|
||||||
|
|
||||||
|
export default class RecipesService implements IRecipesService {
|
||||||
|
private readonly API_URL = "http://localhost:3000/recipes";
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
async getAllRecipes(): Promise<Recipes[]> {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(this.API_URL);
|
||||||
|
return response.data as Recipes[];
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('Erreur lors de la récupération des ingrédients : ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async getRecipeById(id: Number): Promise<Recipes | null>{
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${this.API_URL}/${id}`);
|
||||||
|
console.log(response);
|
||||||
|
return response.data as Recipes;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('Erreur lors de la récupération des ingrédients : ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue