summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/object.go1
-rw-r--r--model/recipe.go14
-rw-r--r--model/recipes.go14
3 files changed, 26 insertions, 3 deletions
diff --git a/model/object.go b/model/object.go
index 63ef419..0b1919b 100644
--- a/model/object.go
+++ b/model/object.go
@@ -9,4 +9,5 @@ type Object interface {
Read(tx *sql.Tx) error
Update(tx *sql.Tx) error
Delete(tx *sql.Tx) error
+ SetID(id int)
}
diff --git a/model/recipe.go b/model/recipe.go
index 684b158..adcafa1 100644
--- a/model/recipe.go
+++ b/model/recipe.go
@@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log"
+ "strconv"
)
type Recipe struct {
@@ -19,11 +21,23 @@ type Recipe struct {
IsFavorite bool `json:"is_favorite"`
}
+func NewRecipe() Object {
+ return &Recipe{}
+}
+
func (r Recipe) String() string {
b, _ := json.MarshalIndent(r, "", " ")
return string(b)
}
+func (r *Recipe) SetID(id int) {
+ if r == nil {
+ log.Println("Got nil as recipe!")
+ }
+
+ r.Id = strconv.Itoa(id)
+}
+
func (r *Recipe) Validate() error {
var err error
diff --git a/model/recipes.go b/model/recipes.go
index e4fd1b8..09b51e7 100644
--- a/model/recipes.go
+++ b/model/recipes.go
@@ -7,13 +7,21 @@ import (
)
type RecipesElement struct {
- Id int64 // TODO change to string
- Title string
- IsFavorite bool
+ Id int64 `json:"id"` // TODO change to string
+ Title string `json:"title"`
+ IsFavorite bool `json:"is_favorite"`
}
type Recipes []RecipesElement
+func NewRecipes() Object {
+ return &Recipes{}
+}
+
+func (r *Recipes) SetID(id int) {
+ // singleton object, ignoring ID
+}
+
func (r *Recipes) Create(tx *sql.Tx) error {
return fmt.Errorf("Impossible to create a recipe list")
}