-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
202 additions
and
38 deletions.
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 |
---|---|---|
|
@@ -46,4 +46,4 @@ | |
"tslint": "~5.15.0", | ||
"typescript": "~3.5.3" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { IRecipe } from '../interfaces/recipe'; | ||
import { IIngredient } from './../interfaces/ingredient'; | ||
|
||
export class Recipe implements IRecipe { | ||
id: number; | ||
title: string; | ||
description: string; | ||
serves: string; | ||
imageUrl: string; | ||
ingredients: IIngredient[]; | ||
instructions: string[]; | ||
|
||
constructor({ id, title, description, serves, imageUrl, ingredients, instructions }) { | ||
this.id = id; | ||
this.title = title; | ||
this.description = description; | ||
this.serves = serves; | ||
this.imageUrl = imageUrl; | ||
this.ingredients = ingredients; | ||
this.instructions = instructions; | ||
} | ||
} |
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,4 @@ | ||
export interface IIngredient { | ||
amount: string; | ||
name: string; | ||
} |
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 { IIngredient } from './ingredient'; | ||
|
||
export interface IRecipe { | ||
id: number; | ||
title: string; | ||
description: string; | ||
serves: string; | ||
imageUrl: string; | ||
ingredients: IIngredient[]; | ||
instructions: string[]; | ||
} |
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,67 @@ | ||
import { Recipe } from './../classes/recipe'; | ||
import { IIngredient } from './../interfaces/ingredient'; | ||
import { Injectable } from '@angular/core'; | ||
import * as recipeData from '../../data.json'; | ||
|
||
@Injectable() | ||
export class RecipeService { | ||
private recipes: Recipe[] = []; | ||
|
||
constructor() { | ||
recipeData.recipes.forEach(recipe => { | ||
this.recipes.push(new Recipe(recipe)); | ||
}); | ||
} | ||
|
||
public getRecipes(): Recipe[] { | ||
return this.recipes; | ||
} | ||
|
||
public getRecipeById(id: number): Recipe { | ||
return this.recipes.find(recipe => recipe.id === id); | ||
} | ||
|
||
public createRecipe( | ||
title: string, | ||
description: string, | ||
serves: string, | ||
imageUrl: string, | ||
ingredients: IIngredient[], | ||
instructions: string[] | ||
) { | ||
const newRecipeData = { | ||
id: this.getNextId(), | ||
title, | ||
description, | ||
serves, | ||
imageUrl, | ||
ingredients: [...ingredients], | ||
instructions: [...instructions] | ||
}; | ||
|
||
const newRecipe = new Recipe(newRecipeData); | ||
|
||
this.recipes.push(newRecipe); | ||
return newRecipe; | ||
} | ||
|
||
public updateRecipe(recipe: Recipe): Recipe { | ||
const recipeIndex = this.recipes.findIndex(r => r.id === recipe.id); | ||
|
||
this.recipes[recipeIndex] = recipe; | ||
return recipe; | ||
} | ||
|
||
public deleteRecipe(id: number): void { | ||
const recipeIndex = this.recipes.findIndex(r => r.id === id); | ||
|
||
if (recipeIndex !== -1) { | ||
this.recipes.splice(recipeIndex, 1); | ||
} | ||
} | ||
|
||
private getNextId(): number { | ||
const max = Math.max.apply(null, this.recipes.map(recipe => recipe.id)); | ||
return max + 1; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,93 @@ | ||
{ | ||
"recipes": [ | ||
{ | ||
"id": 1, | ||
"title": "Best Salad in the World", | ||
"description": "This is a recipe for the best tasting salad in the world. It has lots of carrots and lettuce!", | ||
"serves": "2 people", | ||
"imageUrl": "assets/salad.jpg", | ||
"ingredients": [ | ||
{ | ||
"amount": "1 head", | ||
"name": "lettuce" | ||
}, | ||
{ | ||
"amount": "10", | ||
"name": "carrots" | ||
}, | ||
{ | ||
"amount": "2 tablespoons", | ||
"name": "ranch dressing" | ||
} | ||
], | ||
"instructions": [ | ||
"remove lettuce leaves", | ||
"add lettuce leaves to a large bowl", | ||
"then add the carrots the bowl", | ||
"add the ranch dressing", | ||
"then mix ingredients together in the bowl" | ||
] | ||
}, | ||
{ | ||
"id": 2, | ||
"title": "Chocolate Chip Cookies", | ||
"description": "This was a recipe handed down to me by my grandmother Ruth who use to make the best chocolate chip cookies!", | ||
"serves": "4 people", | ||
"imageUrl": "assets/cookies.jpg", | ||
"ingredients": [ | ||
{ | ||
"amount": "1 bag", | ||
"name": "chocolate chips" | ||
}, | ||
{ | ||
"amount": "2", | ||
"name": "eggs" | ||
}, | ||
{ | ||
"amount": "1 cup", | ||
"name": "flour" | ||
}, | ||
{ | ||
"amount": "1 cup", | ||
"name": "sugar" | ||
} | ||
], | ||
"instructions": [ | ||
"get a large bowl", | ||
"crack eggs into the bowl", | ||
"add the rest of the ingredients to the bowl", | ||
"mix ingredients with a whisk", | ||
"then evenly place small clumps of cookie dough on a baking sheet", | ||
"place baking sheet in oven for 12 minutes at 350 degrees F" | ||
] | ||
}, | ||
{ | ||
"id": 3, | ||
"title": "Cinco de Nachos", | ||
"description": "I discovered this recipe when I went on a trip to Mexico. A nice lady taught me how to make world famous nachos.", | ||
"serves": "2 adults or 4 kids", | ||
"imageUrl": "assets/nachos.jpg", | ||
"ingredients": [ | ||
{ | ||
"amount": "1 bag", | ||
"name": "tortilla chips" | ||
}, | ||
{ | ||
"amount": "1 pound", | ||
"name": "shredded cheese" | ||
}, | ||
{ | ||
"amount": "1 can", | ||
"name": "refried beans" | ||
} | ||
], | ||
"instructions": [ | ||
"spread tortilla chips on a large plate", | ||
"warm up beans in a pot on the stove", | ||
"sprinkle the shredded cheese on top of the chips", | ||
"place plate in the oven for 10 minutes at 350 degrees F", | ||
"finally remove plate from oven and spread refried beans on top of the chips" | ||
] | ||
} | ||
] | ||
} |
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