Changes to pagination and fixing archive messages in progress
This commit is contained in:
@@ -9,9 +9,8 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
templateHelpers "synlotto-website/internal/helpers/template"
|
||||
|
||||
"synlotto-website/internal/helpers"
|
||||
templateHelpers "synlotto-website/internal/helpers/template"
|
||||
"synlotto-website/internal/http/middleware"
|
||||
"synlotto-website/internal/models"
|
||||
)
|
||||
@@ -20,7 +19,6 @@ func ResultsThunderball(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
|
||||
limiter := middleware.GetVisitorLimiter(ip)
|
||||
|
||||
if !limiter.Allow() {
|
||||
http.Error(w, "Rate limit exceeded", http.StatusTooManyRequests)
|
||||
return
|
||||
@@ -46,7 +44,7 @@ func ResultsThunderball(db *sql.DB) http.HandlerFunc {
|
||||
doSearch := isValidDate(query) || isValidNumber(query)
|
||||
|
||||
whereClause := "WHERE 1=1"
|
||||
args := []interface{}{}
|
||||
args := []any{}
|
||||
|
||||
if doSearch {
|
||||
whereClause += " AND (draw_date = ? OR id = ?)"
|
||||
@@ -65,7 +63,21 @@ func ResultsThunderball(db *sql.DB) http.HandlerFunc {
|
||||
args = append(args, ballSetFilter)
|
||||
}
|
||||
|
||||
totalPages, totalResults := templateHelpers.GetTotalPages(db, "results_thunderball", whereClause, args, pageSize)
|
||||
// ✅ FIX: Proper GetTotalPages call with context + correct table name
|
||||
totalPages, totalResults, err := templateHelpers.GetTotalPages(
|
||||
r.Context(),
|
||||
db,
|
||||
"results_thunderball",
|
||||
whereClause,
|
||||
args,
|
||||
pageSize,
|
||||
)
|
||||
if err != nil {
|
||||
log.Println("❌ Pagination count error:", err)
|
||||
http.Error(w, "Database error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if page < 1 || page > totalPages {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
@@ -79,7 +91,7 @@ func ResultsThunderball(db *sql.DB) http.HandlerFunc {
|
||||
LIMIT ? OFFSET ?`
|
||||
argsWithLimit := append(args, pageSize, offset)
|
||||
|
||||
rows, err := db.Query(querySQL, argsWithLimit...)
|
||||
rows, err := db.QueryContext(r.Context(), querySQL, argsWithLimit...)
|
||||
if err != nil {
|
||||
http.Error(w, "Database error", http.StatusInternalServerError)
|
||||
log.Println("❌ DB error:", err)
|
||||
@@ -113,7 +125,7 @@ func ResultsThunderball(db *sql.DB) http.HandlerFunc {
|
||||
noResultsMsg = "No results found for \"" + query + "\""
|
||||
}
|
||||
|
||||
tmpl := templateHelpers.LoadTemplateFiles("thunderball.html", "web/templates/results/thunderball.html")
|
||||
tmpl := templateHelpers.LoadTemplateFiles("layout.html", "web/templates/results/thunderball.html")
|
||||
|
||||
err = tmpl.ExecuteTemplate(w, "layout", map[string]interface{}{
|
||||
"Results": results,
|
||||
|
||||
Reference in New Issue
Block a user