Refactoring cont.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"synlotto-website/helpers"
|
||||
"synlotto-website/models"
|
||||
"synlotto-website/storage"
|
||||
)
|
||||
|
||||
func NewDraw(db *sql.DB) http.HandlerFunc {
|
||||
@@ -19,7 +20,7 @@ func NewDraw(db *sql.DB) http.HandlerFunc {
|
||||
context["Page"] = "new_draw"
|
||||
context["Data"] = nil
|
||||
|
||||
tmpl := templateHelpers.LoadTemplateFiles("new_draw.html", "templates/new_draw.html") // ToDo: may need removing or moving add draw should be admin functionality and only when manually required. Potential live drawing of numbers in the future.
|
||||
tmpl := templateHelpers.LoadTemplateFiles("new_draw.html", "templates/admin/draws/new_draw.html") // ToDo: may need removing or moving add draw should be admin functionality and only when manually required. Potential live drawing of numbers in the future.
|
||||
|
||||
err := tmpl.ExecuteTemplate(w, "layout", context)
|
||||
if err != nil {
|
||||
@@ -29,7 +30,7 @@ func NewDraw(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func Submit(w http.ResponseWriter, r *http.Request) {
|
||||
func Submit(db *sql.DB, w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("📝 Form submission received")
|
||||
_ = r.ParseForm()
|
||||
|
||||
@@ -45,7 +46,12 @@ func Submit(w http.ResponseWriter, r *http.Request) {
|
||||
Thunderball: helpers.Atoi(r.FormValue("thunderball")),
|
||||
}
|
||||
|
||||
Draws = append(Draws, draw)
|
||||
err := storage.InsertThunderballResult(db, draw)
|
||||
if err != nil {
|
||||
log.Println("❌ Failed to insert draw:", err)
|
||||
http.Error(w, "Failed to save draw", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("📅 %s | 🛠 %s | 🎱 %d | 🔢 %d,%d,%d,%d,%d | ⚡ %d\n",
|
||||
draw.DrawDate, draw.Machine, draw.BallSet,
|
||||
|
||||
Reference in New Issue
Block a user