Update
This commit is contained in:
@@ -10,6 +10,7 @@ var Tmpl = template.Must(template.ParseFiles(
|
||||
"templates/index.html",
|
||||
"templates/new_draw.html",
|
||||
"templates/new_ticket.html",
|
||||
"templates/tickets.html",
|
||||
))
|
||||
|
||||
var Draws []models.ThunderballResult
|
||||
|
||||
@@ -48,3 +48,45 @@ func SubmitTicket(db *sql.DB) http.HandlerFunc {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
func ListTickets(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("📋 Tickets page hit")
|
||||
|
||||
rows, err := db.Query(`
|
||||
SELECT id, game_type, draw_date, ball1, ball2, ball3, ball4, ball5, bonus1, bonus2, duplicate
|
||||
FROM my_tickets
|
||||
ORDER BY draw_date DESC
|
||||
`)
|
||||
if err != nil {
|
||||
log.Println("❌ Failed to query tickets:", err)
|
||||
http.Error(w, "Could not load tickets", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var tickets []models.MyTicket
|
||||
for rows.Next() {
|
||||
var t models.MyTicket
|
||||
err := rows.Scan(
|
||||
&t.Id, &t.GameType, &t.DrawDate,
|
||||
&t.Ball1, &t.Ball2, &t.Ball3, &t.Ball4, &t.Ball5,
|
||||
&t.Bonus1, &t.Bonus2, &t.Duplicate,
|
||||
)
|
||||
if err != nil {
|
||||
log.Println("❌ Row scan error:", err)
|
||||
continue
|
||||
}
|
||||
tickets = append(tickets, t)
|
||||
}
|
||||
|
||||
err = Tmpl.ExecuteTemplate(w, "tickets", map[string]any{
|
||||
"Page": "tickets",
|
||||
"Data": tickets,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("❌ Template rendering error:", err)
|
||||
http.Error(w, "Could not render page", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
main.go
2
main.go
@@ -20,6 +20,8 @@ func main() {
|
||||
handlers.Submit(w, r)
|
||||
case "/ticket":
|
||||
handlers.NewTicket(db)
|
||||
case "/tickets":
|
||||
handlers.ListTickets(db)
|
||||
case "/submit-ticket":
|
||||
handlers.SubmitTicket(db)
|
||||
default:
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package models
|
||||
|
||||
type MyTicket struct {
|
||||
Id int
|
||||
GameType string
|
||||
DrawDate string
|
||||
Ball1 int
|
||||
Ball2 int
|
||||
Ball3 int
|
||||
Ball4 int
|
||||
Ball5 int
|
||||
Bonus1 *int
|
||||
Bonus2 *int
|
||||
Id int
|
||||
GameType string
|
||||
DrawDate string
|
||||
Ball1 int
|
||||
Ball2 int
|
||||
Ball3 int
|
||||
Ball4 int
|
||||
Ball5 int
|
||||
Bonus1 *int
|
||||
Bonus2 *int
|
||||
Duplicate bool
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ func InsertThunderballResult(db *sql.DB, res models.ThunderballResult) error {
|
||||
}
|
||||
|
||||
func InsertTicket(db *sql.DB, ticket models.MyTicket) error {
|
||||
// Convert optional fields to interface{} using manual check
|
||||
var bonus1Val interface{}
|
||||
var bonus2Val interface{}
|
||||
|
||||
|
||||
36
templates/tickets.html
Normal file
36
templates/tickets.html
Normal file
@@ -0,0 +1,36 @@
|
||||
{{ define "tickets" }}
|
||||
{{ define "content" }}
|
||||
<a href="/">← Back to Home</a>
|
||||
<h2>My Tickets</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Game</th>
|
||||
<th>Numbers</th>
|
||||
<th>Bonus</th>
|
||||
<th>Duplicate?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range . }}
|
||||
<tr>
|
||||
<td>{{ .DrawDate }}</td>
|
||||
<td>{{ .GameType }}</td>
|
||||
<td>{{ .Ball1 }}, {{ .Ball2 }}, {{ .Ball3 }}, {{ .Ball4 }}, {{ .Ball5 }}</td>
|
||||
<td>
|
||||
{{ if .Bonus1 }}{{ .Bonus1 }}{{ end }}
|
||||
{{ if .Bonus2 }}, {{ .Bonus2 }}{{ end }}
|
||||
</td>
|
||||
<td>
|
||||
{{ if .Duplicate }}⚠️ Yes{{ else }}✔️ No{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
{{ else }}
|
||||
<tr><td colspan="5">No tickets logged yet.</td></tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ template "layout" . }}
|
||||
{{ end }}
|
||||
BIN
tracker.db
BIN
tracker.db
Binary file not shown.
Reference in New Issue
Block a user