From 74855d03f44adf2e77d5d6af38e18e1cfe45e700 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 2 Dec 2019 10:52:47 -0500 Subject: Fix changes json encoding to match frontend --- backend/recipe.go | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/backend/recipe.go b/backend/recipe.go index fed83ca..8589beb 100644 --- a/backend/recipe.go +++ b/backend/recipe.go @@ -5,29 +5,30 @@ 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 + Num int `json:"index"` //Is this needed + 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 { -- cgit v1.1 From 737063651a31b05631fbb3fae5803da5db0ee389 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 2 Dec 2019 10:54:41 -0500 Subject: Fix Ingredients as array in recipe --- recipeBuddy/src/app/DataModels/ingredient.spec.ts | 7 ++++++ recipeBuddy/src/app/DataModels/ingredient.ts | 29 ++++++++++++++++++++++ recipeBuddy/src/app/DataModels/ingredients.spec.ts | 7 ------ recipeBuddy/src/app/DataModels/ingredients.ts | 29 ---------------------- recipeBuddy/src/app/DataModels/recipe.ts | 2 +- 5 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 recipeBuddy/src/app/DataModels/ingredient.spec.ts create mode 100644 recipeBuddy/src/app/DataModels/ingredient.ts delete mode 100644 recipeBuddy/src/app/DataModels/ingredients.spec.ts delete mode 100644 recipeBuddy/src/app/DataModels/ingredients.ts 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/ingredients.spec.ts b/recipeBuddy/src/app/DataModels/ingredients.spec.ts deleted file mode 100644 index 17b5858..0000000 --- a/recipeBuddy/src/app/DataModels/ingredients.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Ingredients } from './ingredients'; - -describe('Ingredients', () => { - it('should create an instance', () => { - expect(new Ingredients()).toBeTruthy(); - }); -}); diff --git a/recipeBuddy/src/app/DataModels/ingredients.ts b/recipeBuddy/src/app/DataModels/ingredients.ts deleted file mode 100644 index 6f96e69..0000000 --- a/recipeBuddy/src/app/DataModels/ingredients.ts +++ /dev/null @@ -1,29 +0,0 @@ -export class Ingredients { - private names: string[]; - private amounts: number[]; - private units: string[]; - private types: string[]; - - public constructor(names: string[], amounts: number[], units: string[], types: string[]) { - this.names = names; - this.amounts = amounts; - this.units = units; - this.types = types; - } - - public getNames(): string[] { - return this.names; - } - - public getAmounts(): number[] { - return this.amounts; - } - - public getUnits(): string[] { - return this.units; - } - - public getTypes(): string[] { - return this.types; - } -} diff --git a/recipeBuddy/src/app/DataModels/recipe.ts b/recipeBuddy/src/app/DataModels/recipe.ts index 82e4a73..7ca7421 100644 --- a/recipeBuddy/src/app/DataModels/recipe.ts +++ b/recipeBuddy/src/app/DataModels/recipe.ts @@ -5,7 +5,7 @@ export class Recipe { private id: number; private name: string; private description: string; - private ingredients: Ingredients; + private ingredients: Ingredient[]; private steps: Steps; private servingSize: number; private cookTime: number; -- cgit v1.1 From 870fb7a7b2faeb9e7e4a99d08d14da61e7b7ad4f Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 2 Dec 2019 10:55:46 -0500 Subject: Fix Steps as array in recipe --- recipeBuddy/src/app/DataModels/recipe.ts | 2 +- recipeBuddy/src/app/DataModels/step.spec.ts | 7 +++++++ recipeBuddy/src/app/DataModels/step.ts | 18 ++++++++++++++++++ recipeBuddy/src/app/DataModels/steps.spec.ts | 7 ------- recipeBuddy/src/app/DataModels/steps.ts | 18 ------------------ 5 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 recipeBuddy/src/app/DataModels/step.spec.ts create mode 100644 recipeBuddy/src/app/DataModels/step.ts delete mode 100644 recipeBuddy/src/app/DataModels/steps.spec.ts delete mode 100644 recipeBuddy/src/app/DataModels/steps.ts diff --git a/recipeBuddy/src/app/DataModels/recipe.ts b/recipeBuddy/src/app/DataModels/recipe.ts index 7ca7421..71cebd0 100644 --- a/recipeBuddy/src/app/DataModels/recipe.ts +++ b/recipeBuddy/src/app/DataModels/recipe.ts @@ -6,7 +6,7 @@ export class Recipe { private name: string; private description: string; private ingredients: Ingredient[]; - private steps: Steps; + private steps: Step[]; private servingSize: number; private cookTime: number; private rating: number; 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; + } + +} diff --git a/recipeBuddy/src/app/DataModels/steps.spec.ts b/recipeBuddy/src/app/DataModels/steps.spec.ts deleted file mode 100644 index e315565..0000000 --- a/recipeBuddy/src/app/DataModels/steps.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Steps } from './steps'; - -describe('Steps', () => { - it('should create an instance', () => { - expect(new Steps()).toBeTruthy(); - }); -}); diff --git a/recipeBuddy/src/app/DataModels/steps.ts b/recipeBuddy/src/app/DataModels/steps.ts deleted file mode 100644 index 9061dc2..0000000 --- a/recipeBuddy/src/app/DataModels/steps.ts +++ /dev/null @@ -1,18 +0,0 @@ -export class Steps { - private instructions: string[]; - private timers: number[]; - - public contructor(instructions: string[], timers: number[]) { - this.instructions = instructions; - this.timers = timers; - } - - public getInstructions(): string[] { - return this.instructions; - } - - public getTimers(): number[] { - return this.timers; - } - -} -- cgit v1.1 From f84d088056974540183aea6184febd0cc94d3635 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 2 Dec 2019 10:57:08 -0500 Subject: Add variables from backend --- recipeBuddy/src/app/DataModels/recipe.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/recipeBuddy/src/app/DataModels/recipe.ts b/recipeBuddy/src/app/DataModels/recipe.ts index 71cebd0..cd121dd 100644 --- a/recipeBuddy/src/app/DataModels/recipe.ts +++ b/recipeBuddy/src/app/DataModels/recipe.ts @@ -9,8 +9,10 @@ export class Recipe { 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,6 +53,9 @@ 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; + } } -- cgit v1.1 From ba3fc1b1ec14035009cbfc642e04fbf1034ce735 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 2 Dec 2019 16:40:03 -0500 Subject: Fix remove Num from Step struct The index of the array can be used instead. --- backend/recipe.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/backend/recipe.go b/backend/recipe.go index 8589beb..a3191c3 100644 --- a/backend/recipe.go +++ b/backend/recipe.go @@ -1,7 +1,6 @@ package main import "database/sql" -import "errors" import "strings" type Ingredient struct { @@ -12,7 +11,6 @@ type Ingredient struct { } type Step struct { - Num int `json:"index"` //Is this needed Desc string `json:"instructions"` Time int `json:"timer"` } @@ -115,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, } @@ -190,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, @@ -280,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) -- cgit v1.1