diff options
author | schencej <55326070+schencej@users.noreply.github.com> | 2019-12-02 16:46:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-02 16:46:52 -0500 |
commit | cafe1b4fd3cc02554f44ffbaa8467d867a6838cb (patch) | |
tree | 3240e099653b60e08b762f814efdc65ea27c9b3b | |
parent | d854dedd5297aaa7901fc2b2b304c8b160830836 (diff) | |
parent | e3340c8df1892356ecf58116db9e910662554eed (diff) |
Merge pull request #11 from tuckerevans/api_json=recipe_object
Api json and recipe object
-rw-r--r-- | backend/recipe.go | 44 | ||||
-rw-r--r-- | recipeBuddy/src/app/DataModels/ingredient.spec.ts | 7 | ||||
-rw-r--r-- | recipeBuddy/src/app/DataModels/ingredient.ts | 29 | ||||
-rw-r--r-- | recipeBuddy/src/app/DataModels/recipe.ts | 15 | ||||
-rw-r--r-- | recipeBuddy/src/app/DataModels/step.spec.ts | 7 | ||||
-rw-r--r-- | recipeBuddy/src/app/DataModels/step.ts | 18 |
6 files changed, 92 insertions, 28 deletions
diff --git a/backend/recipe.go b/backend/recipe.go index fed83ca..a3191c3 100644 --- a/backend/recipe.go +++ b/backend/recipe.go @@ -1,33 +1,32 @@ package main import "database/sql" -import "errors" import "strings" type Ingredient struct { - Name string - Amount float64 - Unit string + Name string `json:"name"` + Amount float64 `json:"amount"` + Unit string `json:"units"` + Type string `json:"type"` } type Step struct { - Num int - Desc string - Time int + Desc string `json:"instructions"` + Time int `json:"timer"` } type Recipe struct { - Id int - Title string - Desc string - Photos []string - Serving_size int - Cook_time int - Rating int - Num_cooked int - Keywords []string - Ingredients []Ingredient - Steps []Step + Id int `json:"id"` + Title string `json:"name"` + Desc string `json:"description"` + Photos []string `json:"photos"` + Serving_size int `json:"servingSize"` + Cook_time int `json:"cookTime"` + Rating int `json:"rating"` + Num_cooked int `json:"timesCooked"` + Keywords []string `json:"tags"` + Ingredients []Ingredient `json:"ingredients"` + Steps []Step `json:"steps"` } func MakeRecipe() *Recipe { @@ -114,13 +113,12 @@ func RecipeFromId(id int, db *sql.DB) *Recipe { var num, timer int rows_steps, err := db.Query(`SELECT step, description, timer - FROM steps WHERE recipe_id = $1`, id) + FROM steps WHERE recipe_id = $1 ORDER BY step`, id) defer rows_steps.Close() if err == nil { for rows_steps.Next() { rows_steps.Scan(&num, &desc, &timer) step = Step{ - Num: num, Desc: desc, Time: timer, } @@ -189,7 +187,7 @@ func AddRecipeDB(r *Recipe, db *sql.DB) error { res, err := tx.Exec(`INSERT INTO steps (step, description, timer, recipe_id) VALUES ($1, $2, $3, $4)`, - step.Num, + i, step.Desc, step.Time, id, @@ -279,10 +277,6 @@ func UpdateRecipeDB(r *Recipe, db *sql.DB) error { } for i, step := range r.Steps { - if step.Num != 0 { - tx.Rollback() - return errors.New("invalid json Recipe") - } _, err := tx.Exec(`INSERT INTO steps (step, description, timer, recipe_id) VALUES ($1, $2, $3, $4) diff --git a/recipeBuddy/src/app/DataModels/ingredient.spec.ts b/recipeBuddy/src/app/DataModels/ingredient.spec.ts new file mode 100644 index 0000000..17b5858 --- /dev/null +++ b/recipeBuddy/src/app/DataModels/ingredient.spec.ts @@ -0,0 +1,7 @@ +import { Ingredients } from './ingredients'; + +describe('Ingredients', () => { + it('should create an instance', () => { + expect(new Ingredients()).toBeTruthy(); + }); +}); diff --git a/recipeBuddy/src/app/DataModels/ingredient.ts b/recipeBuddy/src/app/DataModels/ingredient.ts new file mode 100644 index 0000000..0ede1d1 --- /dev/null +++ b/recipeBuddy/src/app/DataModels/ingredient.ts @@ -0,0 +1,29 @@ +export class Ingredient { + private name: string; + private amount: number; + private unit: string; + private type_: string; + + public constructor(name: string, amount: number, unit: string, type_: string) { + this.name = names; + this.amount = amount; + this.unit = unit; + this.type_ = type_; + } + + public getName(): string { + return this.name; + } + + public getAmount(): number { + return this.amount; + } + + public getUnit(): string { + return this.unit; + } + + public getType(): string { + return this.type_; + } +} diff --git a/recipeBuddy/src/app/DataModels/recipe.ts b/recipeBuddy/src/app/DataModels/recipe.ts index 82e4a73..3194adc 100644 --- a/recipeBuddy/src/app/DataModels/recipe.ts +++ b/recipeBuddy/src/app/DataModels/recipe.ts @@ -5,12 +5,14 @@ export class Recipe { private id: number; private name: string; private description: string; - private ingredients: Ingredients; - private steps: Steps; + private ingredients: Ingredient[]; + private steps: Step[]; private servingSize: number; private cookTime: number; + private timesCooked: number; private rating: number; private tags: string[]; + private photos: string[]; public constructor(id: number, name: string, description: string, ingredients: Ingredients, steps: Steps, servingSize: number, cookTime: number, rating: number, tags: string[]) { this.id = id; @@ -51,7 +53,10 @@ export class Recipe { public getCookTime(): number { return this.cookTime; } - + + public getTimesCooked(): number { + return timesCooked; + } public getRating(): number { return this.rating; } @@ -59,4 +64,8 @@ export class Recipe { public getTags(): string[] { return this.tags; } + + public getPhotos(): string[] { + return this.photos; + } } diff --git a/recipeBuddy/src/app/DataModels/step.spec.ts b/recipeBuddy/src/app/DataModels/step.spec.ts new file mode 100644 index 0000000..e315565 --- /dev/null +++ b/recipeBuddy/src/app/DataModels/step.spec.ts @@ -0,0 +1,7 @@ +import { Steps } from './steps'; + +describe('Steps', () => { + it('should create an instance', () => { + expect(new Steps()).toBeTruthy(); + }); +}); diff --git a/recipeBuddy/src/app/DataModels/step.ts b/recipeBuddy/src/app/DataModels/step.ts new file mode 100644 index 0000000..674a6df --- /dev/null +++ b/recipeBuddy/src/app/DataModels/step.ts @@ -0,0 +1,18 @@ +export class Steps { + private instruction: string; + private timer: number; + + public contructor(instruction: string, timer: number) { + this.instruction = instruction; + this.timer = timer; + } + + public getInstruction(): string { + return this.instruction; + } + + public getTimer(): number { + return this.timer; + } + +} |