diff options
Diffstat (limited to 'model/recipes.go')
-rw-r--r-- | model/recipes.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/model/recipes.go b/model/recipes.go index 324589a..e4fd1b8 100644 --- a/model/recipes.go +++ b/model/recipes.go @@ -7,8 +7,9 @@ import ( ) type RecipesElement struct { - Id int64 // TODO change to string - Title string + Id int64 // TODO change to string + Title string + IsFavorite bool } type Recipes []RecipesElement @@ -22,7 +23,7 @@ func (r *Recipes) Read(tx *sql.Tx) error { return errors.New("Recipes has to contain zero elements for .Read()") } - query := `SELECT id, title FROM recipes` + query := `SELECT id, title, is_favorite FROM recipes ORDER BY is_favorite DESC, created DESC` rows, err := tx.Query(query) if err != nil { @@ -32,7 +33,7 @@ func (r *Recipes) Read(tx *sql.Tx) error { for rows.Next() { element := RecipesElement{} - err = rows.Scan(&element.Id, &element.Title) + err = rows.Scan(&element.Id, &element.Title, &element.IsFavorite) if err != nil { return err } @@ -53,12 +54,14 @@ func (r *Recipes) Delete(tx *sql.Tx) error { func RecipesTestData() Recipes { return []RecipesElement{ { - Id: 1, - Title: "Pancakes", + Id: 1, + Title: "Pancakes", + IsFavorite: true, }, { - Id: 2, - Title: "Burger", + Id: 2, + Title: "Burger", + IsFavorite: false, }, } } |