From 325a2740e39b7c7937bfae8b76b092dd900fec9a Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 17 Jan 2024 21:37:52 +0100 Subject: Show steps on recipe page --- model/recipe.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'model/recipe.go') diff --git a/model/recipe.go b/model/recipe.go index 2b3953f..c6aa63c 100644 --- a/model/recipe.go +++ b/model/recipe.go @@ -6,6 +6,7 @@ type Recipe struct { Portions string // FIXME has to be uint URL string Notes string + Steps []RecipeStep } func (d *Recipe) FromDB() error { @@ -14,13 +15,36 @@ func (d *Recipe) FromDB() error { return err } - return db.QueryRow(query, d.Id).Scan( + err = db.QueryRow(query, d.Id).Scan( &d.Id, &d.Title, &d.Portions, &d.URL, &d.Notes, ) + if err != nil { + return err + } + + query, err = GetSql(`steps-for-recipe`) + if err != nil { + return err + } + + rows, err := db.Query(query, d.Id) + if err != nil { + return err + } + for rows.Next() { + var step RecipeStep + err = rows.Scan(&step.Text) + if err != nil { + return err + } + d.Steps = append(d.Steps, step) + } + + return nil } func (d *Recipe) ToDB() error { -- cgit v1.2.3-70-g09d2