summaryrefslogtreecommitdiff
path: root/controller/common.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-01-08 19:36:01 +0100
committerxengineering <me@xengineering.eu>2024-01-08 19:36:01 +0100
commitae1a31f226de5701683231afaabf0f66503ca17d (patch)
treeb11a8b8c91ac41ee7ffb783de23b5c38dd9e2e6a /controller/common.go
parent43e7bb10eaade56a9444ec089aa3102218231868 (diff)
downloadceres-ae1a31f226de5701683231afaabf0f66503ca17d.tar
ceres-ae1a31f226de5701683231afaabf0f66503ca17d.tar.zst
ceres-ae1a31f226de5701683231afaabf0f66503ca17d.zip
Implement recipe editing
Diffstat (limited to 'controller/common.go')
-rw-r--r--controller/common.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/controller/common.go b/controller/common.go
new file mode 100644
index 0000000..014c001
--- /dev/null
+++ b/controller/common.go
@@ -0,0 +1,37 @@
+package controller
+
+import (
+ "net/http"
+
+ "xengineering.eu/ceres/model"
+
+ "github.com/gorilla/mux"
+)
+
+func RecipePost(w http.ResponseWriter, r *http.Request) {
+ var data model.Recipe
+ var err error
+
+ vars := mux.Vars(r)
+ data.Id = vars[`id`]
+
+ err = r.ParseForm()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ // TODO error handling and generic implementation
+ data.Title = r.PostForm[`title`][0]
+ data.Portions = r.PostForm[`portions`][0]
+ data.URL = r.PostForm[`url`][0]
+ data.Notes = r.PostForm[`notes`][0]
+
+ err = data.ToDB()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ http.Redirect(w, r, r.URL.Path, http.StatusSeeOther)
+}