From b79621cf9f63ea56d17fbcc468f808aabeacdfa3 Mon Sep 17 00:00:00 2001 From: H3ALY Date: Tue, 1 Apr 2025 16:01:33 +0100 Subject: [PATCH] Should not be in template.go should be template functions. --- handlers/template.go | 54 -------------------------------------------- 1 file changed, 54 deletions(-) diff --git a/handlers/template.go b/handlers/template.go index 4c5dc37..4db2eac 100644 --- a/handlers/template.go +++ b/handlers/template.go @@ -1,13 +1,7 @@ package handlers import ( - "database/sql" "html/template" - "log" - "net/http" - - "synlotto-website/helpers" - "synlotto-website/models" ) func templateFuncs() template.FuncMap { @@ -29,51 +23,3 @@ func templateFuncs() template.FuncMap { }, } } - -func NewDraw(db *sql.DB) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - log.Println("➡️ New draw form opened") - - context := BuildTemplateContext(db, w, r) - context["Page"] = "new_draw" - context["Data"] = nil - - tmpl := template.Must(template.New("").Funcs(templateFuncs()).ParseFiles( - "templates/layout.html", - "templates/topbar.html", - "templates/new_draw.html", - )) - - err := tmpl.ExecuteTemplate(w, "layout", context) - if err != nil { - log.Println("❌ Template error:", err) - http.Error(w, "Error rendering form", http.StatusInternalServerError) - } - } -} - -func Submit(w http.ResponseWriter, r *http.Request) { - log.Println("📝 Form submission received") - _ = r.ParseForm() - - draw := models.ThunderballResult{ - DrawDate: r.FormValue("date"), - Machine: r.FormValue("machine"), - BallSet: helpers.Atoi(r.FormValue("ballSet")), - Ball1: helpers.Atoi(r.FormValue("ball1")), - Ball2: helpers.Atoi(r.FormValue("ball2")), - Ball3: helpers.Atoi(r.FormValue("ball3")), - Ball4: helpers.Atoi(r.FormValue("ball4")), - Ball5: helpers.Atoi(r.FormValue("ball5")), - Thunderball: helpers.Atoi(r.FormValue("thunderball")), - } - - // For now you're appending to memory - can replace with DB insert later - Draws = append(Draws, draw) - - log.Printf("📅 %s | 🖠 %s | 🎱 %d | 🔢 %d,%d,%d,%d,%d | ⚡ %d\n", - draw.DrawDate, draw.Machine, draw.BallSet, - draw.Ball1, draw.Ball2, draw.Ball3, draw.Ball4, draw.Ball5, draw.Thunderball) - - http.Redirect(w, r, "/", http.StatusSeeOther) -}