From 49ffaf0aac14272c2f64a3005ad651b78eb51ad1 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 12 Mar 2024 21:25:19 +0100 Subject: model: Remove .Touch() method The model package should never modify the data. Thus the functionality to update timestamps is moved to the controller package which is intended to modify data. --- controller/recipe.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'controller') diff --git a/controller/recipe.go b/controller/recipe.go index 6acb062..09f65a7 100644 --- a/controller/recipe.go +++ b/controller/recipe.go @@ -2,8 +2,10 @@ package controller import ( "encoding/json" + "fmt" "io" "net/http" + "time" "xengineering.eu/ceres/model" @@ -13,7 +15,7 @@ import ( func RecipeCreate(w http.ResponseWriter, r *http.Request) { recipe := model.Recipe{} recipe.Title = "recipe without title" - recipe.Touch() + recipe.LastChanged = fmt.Sprint(time.Now().Unix()) recipe.Created = recipe.LastChanged err := recipe.Create() @@ -22,7 +24,7 @@ func RecipeCreate(w http.ResponseWriter, r *http.Request) { return } - http.Redirect(w, r, "/recipe/" + recipe.Id + "?view=recipe-edit", http.StatusSeeOther) + http.Redirect(w, r, "/recipe/"+recipe.Id+"?view=recipe-edit", http.StatusSeeOther) } func RecipeUpdate(w http.ResponseWriter, r *http.Request) { @@ -44,7 +46,7 @@ func RecipeUpdate(w http.ResponseWriter, r *http.Request) { return } - recipe.Touch() + recipe.LastChanged = fmt.Sprint(time.Now().Unix()) err = recipe.Update() if err != nil { @@ -52,7 +54,7 @@ func RecipeUpdate(w http.ResponseWriter, r *http.Request) { return } - http.Redirect(w, r, "/recipe/" + recipe.Id, http.StatusSeeOther) + http.Redirect(w, r, "/recipe/"+recipe.Id, http.StatusSeeOther) } func RecipeDelete(w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3-70-g09d2