From 73a5c7fae9ffbe9ada721148c8c454a643aceebe Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 20 Feb 2022 16:11:50 +0100 Subject: chore!: restructure repo I separated public files from the config/dev files. It improves repo readability. I also moved dotenv helper to public/inc directory and extract the Matomo tracker in the same directory. --- .../src/app/shared/services/recipes.service.ts | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 public/projects/angular-small-apps/apps/recipes/src/app/shared/services/recipes.service.ts (limited to 'public/projects/angular-small-apps/apps/recipes/src/app/shared/services/recipes.service.ts') diff --git a/public/projects/angular-small-apps/apps/recipes/src/app/shared/services/recipes.service.ts b/public/projects/angular-small-apps/apps/recipes/src/app/shared/services/recipes.service.ts new file mode 100644 index 0000000..a82e019 --- /dev/null +++ b/public/projects/angular-small-apps/apps/recipes/src/app/shared/services/recipes.service.ts @@ -0,0 +1,46 @@ +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { Recipes } from '../recipes'; + +@Injectable({ + providedIn: 'root', +}) +export class RecipesService { + private allRecipesAPI = + 'https://www.themealdb.com/api/json/v1/1/search.php?f=a'; + private recipeByIdAPI = + 'https://www.themealdb.com/api/json/v1/1/lookup.php?i='; + private recipeByNameAPI = + 'https://www.themealdb.com/api/json/v1/1/search.php?s='; + private recipeByIngredientAPI = + 'https://www.themealdb.com/api/json/v1/1/filter.php?i='; + private recipeByCategoryAPI = + 'https://www.themealdb.com/api/json/v1/1/filter.php?c='; + + httpOptions = { + headers: new HttpHeaders({ 'Content-Type': 'application/json' }), + }; + + constructor(private http: HttpClient) {} + + getAllRecipes(): Observable { + return this.http.get(this.allRecipesAPI); + } + + getRecipeById(id: number): Observable { + return this.http.get(this.recipeByIdAPI + id); + } + + getRecipeByName(name: string): Observable { + return this.http.get(this.recipeByNameAPI + name); + } + + getRecipeByIngredient(ingredient: string): Observable { + return this.http.get(this.recipeByIngredientAPI + ingredient); + } + + getRecipeByCategory(category: string): Observable { + return this.http.get(this.recipeByCategoryAPI + category); + } +} -- cgit v1.2.3