summaryrefslogtreecommitdiff
path: root/view/recipe.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-02-12 20:33:24 +0100
committerxengineering <me@xengineering.eu>2024-02-13 20:26:47 +0100
commitbf0ad86df2e64191f6c430c328fee211ac3affa7 (patch)
tree6bde15b19d89cc31c9ed6e42a4cbccfb6dd6c4c8 /view/recipe.go
parent40868be7d4b9e1d9909a19dccc25ec49c1b5924b (diff)
downloadceres-bf0ad86df2e64191f6c430c328fee211ac3affa7.tar
ceres-bf0ad86df2e64191f6c430c328fee211ac3affa7.tar.zst
ceres-bf0ad86df2e64191f6c430c328fee211ac3affa7.zip
view: Implement GET handler for model.Recipe
Diffstat (limited to 'view/recipe.go')
-rw-r--r--view/recipe.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/view/recipe.go b/view/recipe.go
new file mode 100644
index 0000000..3739143
--- /dev/null
+++ b/view/recipe.go
@@ -0,0 +1,30 @@
+package view
+
+import (
+ "net/http"
+ "strconv"
+
+ "xengineering.eu/ceres/model"
+
+ "github.com/gorilla/mux"
+)
+
+func Recipe(w http.ResponseWriter, r *http.Request) {
+ id_str := mux.Vars(r)[`id`]
+ id, _ := strconv.Atoi(id_str)
+
+ recipe := model.Recipe{}
+ recipe.Id = int64(id)
+
+ err := recipe.Read()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ err = html.ExecuteTemplate(w, "recipe", recipe)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}