summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-02-17 17:51:00 +0100
committerxengineering <me@xengineering.eu>2024-03-03 14:00:10 +0100
commite105822a4f2227ca97853ac1bf106f8d204d6837 (patch)
treec41dad467fe04b645543644a4bd6f5c86b77f232 /model
parent55b69380ebd704477c4a37ff9b70fcb3cbdc63e5 (diff)
downloadceres-e105822a4f2227ca97853ac1bf106f8d204d6837.tar
ceres-e105822a4f2227ca97853ac1bf106f8d204d6837.tar.zst
ceres-e105822a4f2227ca97853ac1bf106f8d204d6837.zip
controller: Update recipe based on JSON
Diffstat (limited to 'model')
-rw-r--r--model/recipe.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/model/recipe.go b/model/recipe.go
index 760fe79..c9ef6fb 100644
--- a/model/recipe.go
+++ b/model/recipe.go
@@ -17,10 +17,14 @@ type Recipe struct {
LastChanged string `json:"last_changed"`
}
-func (r *Recipe) Create() error {
+func (r *Recipe) Touch() {
now := time.Now().Unix()
- r.Created = fmt.Sprint(now)
- r.LastChanged = r.Created
+ r.LastChanged = fmt.Sprint(now)
+}
+
+func (r *Recipe) Create() error {
+ r.Touch()
+ r.Created = r.LastChanged
query := `INSERT INTO recipes
(title, portions, url, notes, created, last_changed)
@@ -78,6 +82,8 @@ WHERE id = ?`
}
func (r *Recipe) Update() error {
+ r.Touch()
+
query := `UPDATE
recipes
SET
@@ -85,13 +91,12 @@ SET
portions = ?,
url = ?,
notes = ?,
- created = ?,
last_changed = ?
WHERE
id = ?`
res, err := db.Exec(query, r.Title, r.Portions, r.Url, r.Notes,
- r.Created, r.LastChanged, r.Id)
+ r.LastChanged, r.Id)
if err != nil {
return err
}