diff options
-rw-r--r-- | backend/readme.adoc | 13 | ||||
-rw-r--r-- | backend/recipe.go | 5 | ||||
-rw-r--r-- | recipeBuddy/src/app/add-recipe/add-recipe.component.ts | 18 |
3 files changed, 19 insertions, 17 deletions
diff --git a/backend/readme.adoc b/backend/readme.adoc index b10ea07..bc3c50f 100644 --- a/backend/readme.adoc +++ b/backend/readme.adoc @@ -37,12 +37,11 @@ The current implementation expects (and returns) recipes in the form: "name": "Ingredient 1 Name", "amount": 1.0, "unit": "Ingredient Units" - "type_": "" }, ], "steps": [ { - "instructions": "Step Instructions/Description", + "instruction": "Step Instructions/Description", "timer": 0 } ] @@ -122,11 +121,11 @@ $ curl -X POST api.recipebuddy.xyz:8888/recipes -d ' {"name":"INGR 2","amount":1,"unit":"oz"} ], "steps":[ - {"instructions":"Step 1: Do this first","timer":10} + {"instruction":"Step 1: Do this first","timer":10} ] }' -{"Status":{"Code":201,"Msg":"Recipe added successfully"},"Data":{"id":2,"name":"Test Recipe 2","description":"This is a descripiton for the test recipe","photos":["photo_url_1","photo_url_2"],"servingSize":0,"cookTime":60,"rating":5,"timesCooked":0,"tags":["keyword_1","keyword_2","keyword_3"],"ingredients":[{"name":"INGR 1","amount":2.5,"unit":"cups"},{"name":"INGR 2","amount":1,"unit":"oz"}],"steps":[{"instructions":"Step 1: Do this first","timer":10}]}} +{"Status":{"Code":201,"Msg":"Recipe added successfully"},"Data":{"id":2,"name":"Test Recipe 2","description":"This is a descripiton for the test recipe","photos":["photo_url_1","photo_url_2"],"servingSize":0,"cookTime":60,"rating":5,"timesCooked":0,"tags":["keyword_1","keyword_2","keyword_3"],"ingredients":[{"name":"INGR 1","amount":2.5,"unit":"cups"},{"name":"INGR 2","amount":1,"unit":"oz"}],"steps":[{"instruction":"Step 1: Do this first","timer":10}]}} ---- Read @@ -138,7 +137,7 @@ http://api.recipebuddy.xyz:8888/recipes/0[`/recipes/{id}`], the HTTP body is ign ---- $ curl -X GET api.recipebuddy.xyz:8888/recipes/1 -{"Status":{"Code":200,"Msg":"Successful"},"Data":{"id":1,"name":"Test Recipe","description":"This is a descripiton for the test recipe","photos":["photo_url_1","photo_url_2",""],"servingSize":0,"cookTime":60,"rating":5,"timesCooked":0,"tags":["keyword_1","keyword_2","keyword_3",""],"ingredients":[{"name":"INGR 1","amount":2.5,"unit":"cups"},{"name":"INGR 2","amount":1,"unit":"oz"}],"steps":[{"instructions":"Step 1: Do this first","timer":10}]}} +{"Status":{"Code":200,"Msg":"Successful"},"Data":{"id":1,"name":"Test Recipe","description":"This is a descripiton for the test recipe","photos":["photo_url_1","photo_url_2",""],"servingSize":0,"cookTime":60,"rating":5,"timesCooked":0,"tags":["keyword_1","keyword_2","keyword_3",""],"ingredients":[{"name":"INGR 1","amount":2.5,"unit":"cups"},{"name":"INGR 2","amount":1,"unit":"oz"}],"steps":[{"instruction":"Step 1: Do this first","timer":10}]}} ---- To access a list of all recipe ids in the database send a `GET` request to @@ -171,11 +170,11 @@ $ curl -X PUT localhost:8888/recipes/1 -d ' { "name":"INGR 2", "amount":1, "unit":"oz" } ], "steps":[ - { "instructions":"Step 1: Do this first", "timer":10 } + { "instruction":"Step 1: Do this first", "timer":10 } ] }' -{"Status":{"Code":201,"Msg":"Recipe added successfully"},"Data":{"id":1,"name":"Test Recipe 1","description":"This is a descripiton for the test recipe","photos":["photo_url_1","photo_url_2"],"servingSize":0,"cookTime":60,"rating":5,"timesCooked":0,"tags":["keyword_1","keyword_2","keyword_3"],"ingredients":[{"name":"INGR 1","amount":2.5,"unit":"cups"},{"name":"INGR 2","amount":1,"unit":"oz"}],"steps":[{"instructions":"Step 1: Do this first","timer":10}]}} +{"Status":{"Code":201,"Msg":"Recipe added successfully"},"Data":{"id":1,"name":"Test Recipe 1","description":"This is a descripiton for the test recipe","photos":["photo_url_1","photo_url_2"],"servingSize":0,"cookTime":60,"rating":5,"timesCooked":0,"tags":["keyword_1","keyword_2","keyword_3"],"ingredients":[{"name":"INGR 1","amount":2.5,"unit":"cups"},{"name":"INGR 2","amount":1,"unit":"oz"}],"steps":[{"instruction":"Step 1: Do this first","timer":10}]}} ---- [WARNING] diff --git a/backend/recipe.go b/backend/recipe.go index a3191c3..59b7366 100644 --- a/backend/recipe.go +++ b/backend/recipe.go @@ -6,12 +6,11 @@ import "strings" type Ingredient struct { Name string `json:"name"` Amount float64 `json:"amount"` - Unit string `json:"units"` - Type string `json:"type"` + Unit string `json:"unit"` } type Step struct { - Desc string `json:"instructions"` + Desc string `json:"instruction"` Time int `json:"timer"` } diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts index 407997c..5109c34 100644 --- a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts +++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts @@ -7,6 +7,8 @@ import { FormArray } from '@angular/forms'; import { Validators } from '@angular/forms'; +import { Router } from '@angular/router'; + import { Recipe } from '../DataModels/recipe'; import { Ingredient } from '../DataModels/ingredient' import { Step } from '../DataModels/step'; @@ -43,7 +45,8 @@ export class AddRecipeComponent { }); constructor(private fb: FormBuilder, - private restService: BackendService + private restService: BackendService, + private router: Router, ) { } ngOnInit() { @@ -99,9 +102,9 @@ export class AddRecipeComponent { } var steps = [] - for (i = 0; i < formData.ingredients.length; i++) { - var tmp_timer = parseInt(formData.steps[0].timer) - steps.push(new Step(formData.steps[0].instruct, + for (i = 0; i < formData.steps.length; i++) { + var tmp_timer = parseInt(formData.steps[i].timer) + steps.push(new Step(formData.steps[i].instruct, (isNaN(tmp_timer) ? 0 : tmp_timer) )); } @@ -118,9 +121,10 @@ export class AddRecipeComponent { (isNaN(cookTimeTmp) ? 0 :cookTimeTmp), //cookTime 0, //timesCooked 0, //rating - formData.tags.split(','), //tags - formData.photos.split(',') //photos + formData.tags.split(',').filter(word=> !(word==="")), //tags + formData.photos.split(',').filter(word=> !(word==="")) //photos ); - this.restService.createRecipe(recipe).subscribe() + this.restService.createRecipe(recipe).subscribe(); + this.router.navigate(['/']); } } |