Feature: Full notification read view with conditional mark-as-read logic

- Added dedicated route and view for reading individual notifications (/account/notifications/read)
- Ensured notification is only marked as read if it hasn't already been
- Updated Notification model to use Subject and Body fields
- Fixed field references in templates (Title → Subject, Message → Body)
- Updated topbar dropdown to use correct field names and display logic
- Gracefully handle "notification not found" cases in template output
- Ensured consistent template parsing with layout and topbar inclusion
- Improved error logging for better diagnosis
This commit is contained in:
2025-04-01 23:08:58 +01:00
parent 06e647d00f
commit e5bf12ad77
10 changed files with 110 additions and 69 deletions

View File

@@ -5,60 +5,23 @@ import (
"html/template"
"log"
"net/http"
"sort"
"synlotto-website/helpers"
"synlotto-website/models"
)
// Home shows latest Thunderball results
func Home(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
rows, err := db.Query(`
SELECT id, draw_date, machine, ballset, ball1, ball2, ball3, ball4, ball5, thunderball
FROM results_thunderball
ORDER BY id DESC
`)
if err != nil {
log.Println("❌ DB error:", err)
http.Error(w, "Database error", http.StatusInternalServerError)
return
}
defer rows.Close()
var results []models.ThunderballResult
for rows.Next() {
var res models.ThunderballResult
err := rows.Scan(
&res.Id, &res.DrawDate, &res.Machine, &res.BallSet,
&res.Ball1, &res.Ball2, &res.Ball3, &res.Ball4, &res.Ball5, &res.Thunderball,
)
if err != nil {
log.Println("❌ Row scan error:", err)
continue
}
res.SortedBalls = []int{
res.Ball1, res.Ball2, res.Ball3, res.Ball4, res.Ball5,
}
sort.Ints(res.SortedBalls)
results = append(results, res)
}
data := BuildTemplateData(db, w, r)
context := helpers.TemplateContext(w, r, data)
context["Data"] = results
tmpl := template.Must(template.New("").Funcs(helpers.TemplateFuncs()).ParseFiles(
tmpl := template.Must(template.New("index.html").Funcs(helpers.TemplateFuncs()).ParseFiles(
"templates/layout.html",
"templates/topbar.html",
"templates/index.html",
))
err = tmpl.ExecuteTemplate(w, "layout", context)
err := tmpl.ExecuteTemplate(w, "layout", context)
if err != nil {
log.Println("❌ Template error:", err)
log.Println("❌ Template render error:", err)
http.Error(w, "Error rendering homepage", http.StatusInternalServerError)
}
}