From 7bb54a56e993723b2867efbafddd1b9abfebcd9e Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Sat, 22 Apr 2023 19:28:54 +0200
Subject: Remove legacy Recipe struct

---
 handler.go | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

(limited to 'handler.go')

diff --git a/handler.go b/handler.go
index 8a514e7..c234d3d 100644
--- a/handler.go
+++ b/handler.go
@@ -15,18 +15,9 @@ const (
 	VALID_ID_REGEX = `^[0-9]+$`
 )
 
-type Recipe struct {
-	Id    string
-	Title string
-	Text  string
-	Html  string
-}
-
 func indexGet(w http.ResponseWriter, r *http.Request) {
 	list := getRecipeList()
-
 	sort.Sort(list)
-
 	ServeTemplate(w, "index.html", list)
 }
 
@@ -64,16 +55,17 @@ func recipeEditGet(w http.ResponseWriter, r *http.Request) {
 	}
 	idStr := ids[0]
 
-	textpath := filepath.Join(config.Data, "recipes", idStr, "text")
-	data, _ := ioutil.ReadFile(textpath)
-
-	recipe := Recipe{
-		idStr,
-		"",
-		string(data),
-		"",
+	text, err := getRecipeText(idStr)
+	if err != nil {
+		http.Error(w, "Could not get recipe.", 400)
+		return
 	}
 
+	recipe := struct{
+		Id   string
+		Text string
+	}{idStr, string(text)}
+
 	ServeTemplate(w, "recipe_edit.html", recipe)
 }
 
@@ -113,9 +105,7 @@ func recipeConfirmDeletionGet(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	recipe := Recipe{ids[0], "", "", ""}
-
-	ServeTemplate(w, "recipe_confirm_deletion.html", recipe)
+	ServeTemplate(w, "recipe_confirm_deletion.html", struct{Id string}{ids[0]})
 }
 
 func recipeConfirmDeletionPost(w http.ResponseWriter, r *http.Request) {
-- 
cgit v1.2.3-70-g09d2