|
|
|
@@ -3,19 +3,24 @@ import { HttpClient } from '@angular/common/http' |
|
|
|
|
|
|
|
import { RecipeService } from '../recipes/recipe.service'; |
|
|
|
import { Recipe } from '../recipes/recipe.model'; |
|
|
|
import { AuthService } from '../auth/auth.service'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class DataStorageService { |
|
|
|
readonly baseUrl: string = 'https://my-recipe-book-cb837.firebaseio.com/'; |
|
|
|
|
|
|
|
constructor(private httpClient: HttpClient, private recipeService: RecipeService) {} |
|
|
|
constructor(private httpClient: HttpClient, |
|
|
|
private recipeService: RecipeService, |
|
|
|
private authService: AuthService) {} |
|
|
|
|
|
|
|
storeRecipes() { |
|
|
|
return this.httpClient.put(this.baseUrl + 'recipes.json', this.recipeService.getRecipes()); |
|
|
|
const token = this.authService.getToken(); |
|
|
|
return this.httpClient.put(this.baseUrl + 'recipes.json?auth=' + token, this.recipeService.getRecipes()); |
|
|
|
} |
|
|
|
|
|
|
|
fetchRecipes() { |
|
|
|
this.httpClient.get<Recipe[]>(this.baseUrl + 'recipes.json').subscribe( |
|
|
|
const token = this.authService.getToken(); |
|
|
|
this.httpClient.get<Recipe[]>(this.baseUrl + 'recipes.json?auth=' + token).subscribe( |
|
|
|
recipes => { |
|
|
|
this.recipeService.replaceRecipes(recipes); |
|
|
|
} |
|
|
|
|