Cleanup: Finalize template context integration and remove legacy code

- Replaced legacy TemplateContext calls with structured TemplateData usage
- Removed unused variables and redundant storage calls in notifications handler
- Ensured consistent use of BuildTemplateData across user-facing handlers
- Resolved all compile-time errors from refactor
- Ready for runtime testing and further layout integration
This commit is contained in:
2025-04-01 21:20:05 +01:00
parent 03b1e095ce
commit 5ea780fcab
11 changed files with 35 additions and 45 deletions

View File

@@ -20,7 +20,7 @@ type AdminLogEntry struct {
func AdminAccessLogHandler(db *sql.DB) http.HandlerFunc {
return middleware.Auth(true)(func(w http.ResponseWriter, r *http.Request) {
context := helpers.TemplateContext(w, r)
context := helpers.TemplateContext(w, r, models.TemplateData{})
rows, err := db.Query(`
SELECT accessed_at, user_id, path, ip, user_agent
@@ -56,7 +56,7 @@ func AdminAccessLogHandler(db *sql.DB) http.HandlerFunc {
func AuditLogHandler(db *sql.DB) http.HandlerFunc {
return middleware.Auth(true)(func(w http.ResponseWriter, r *http.Request) {
context := helpers.TemplateContext(w, r)
context := helpers.TemplateContext(w, r, models.TemplateData{})
rows, err := db.Query(`
SELECT timestamp, user_id, action, ip, user_agent

View File

@@ -20,7 +20,7 @@ func AdminDashboardHandler(db *sql.DB) http.HandlerFunc {
// TODO: check is_admin from users table here
context := helpers.TemplateContext(w, r)
context := helpers.TemplateContext(w, r, models.TemplateData{})
// Total ticket stats
var total, winners int

View File

@@ -12,7 +12,7 @@ import (
func NewDrawHandler(db *sql.DB) http.HandlerFunc {
return helpers.AuthMiddleware(func(w http.ResponseWriter, r *http.Request) {
context := helpers.TemplateContext(w, r)
context := helpers.TemplateContext(w, r, models.TemplateData{})
if r.Method == http.MethodPost {
game := r.FormValue("game_type")
@@ -75,7 +75,7 @@ func DeleteDrawHandler(db *sql.DB) http.HandlerFunc {
func ListDrawsHandler(db *sql.DB) http.HandlerFunc {
return helpers.AuthMiddleware(func(w http.ResponseWriter, r *http.Request) {
context := helpers.TemplateContext(w, r)
context := helpers.TemplateContext(w, r, models.TemplateData{})
draws := []models.DrawSummary{}
rows, err := db.Query(`

View File

@@ -10,12 +10,13 @@ import (
"strconv"
"synlotto-website/helpers"
"synlotto-website/models"
services "synlotto-website/services/tickets"
)
func AdminTriggersHandler(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
context := helpers.TemplateContext(w, r)
context := helpers.TemplateContext(w, r, models.TemplateData{})
// Inject flash message if available
if flash := r.URL.Query().Get("flash"); flash != "" {

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"strconv"
"synlotto-website/helpers"
"synlotto-website/models"
)
func AddPrizesHandler(db *sql.DB) http.HandlerFunc {
@@ -16,7 +17,7 @@ func AddPrizesHandler(db *sql.DB) http.HandlerFunc {
"templates/layout.html",
"templates/admin/draws/prizes/add_prizes.html",
))
tmpl.ExecuteTemplate(w, "layout", helpers.TemplateContext(w, r))
tmpl.ExecuteTemplate(w, "layout", helpers.TemplateContext(w, r, models.TemplateData{}))
return
}
@@ -50,7 +51,7 @@ func ModifyPrizesHandler(db *sql.DB) http.HandlerFunc {
"templates/layout.html",
"templates/admin/draws/prizes/modify_prizes.html",
))
tmpl.ExecuteTemplate(w, "layout", helpers.TemplateContext(w, r))
tmpl.ExecuteTemplate(w, "layout", helpers.TemplateContext(w, r, models.TemplateData{}))
return
}