Fix for tim.Time change to tickets model includes date helper.
This commit is contained in:
@@ -145,16 +145,24 @@ func SyndicateLogTicketHandler(app *bootstrap.App) http.HandlerFunc {
|
||||
|
||||
case http.MethodPost:
|
||||
gameType := r.FormValue("game_type")
|
||||
drawDate := r.FormValue("draw_date")
|
||||
drawDateStr := r.FormValue("draw_date")
|
||||
method := r.FormValue("purchase_method")
|
||||
|
||||
err := ticketStorage.InsertTicket(app.DB, models.Ticket{
|
||||
dt, err := helpers.ParseDrawDate(drawDateStr)
|
||||
if err != nil {
|
||||
templateHelpers.SetFlash(r, "Invalid draw date")
|
||||
http.Redirect(w, r, fmt.Sprintf("/syndicate/view?id=%d", syndicateId), http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
err = ticketStorage.InsertTicket(app.DB, models.Ticket{
|
||||
UserId: userID,
|
||||
GameType: gameType,
|
||||
DrawDate: drawDate,
|
||||
DrawDate: dt,
|
||||
PurchaseMethod: method,
|
||||
SyndicateId: &syndicateId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
templateHelpers.SetFlash(r, "Failed to add ticket.")
|
||||
} else {
|
||||
|
||||
@@ -74,10 +74,18 @@ func AddTicket(app *bootstrap.App) http.HandlerFunc {
|
||||
}
|
||||
|
||||
game := r.FormValue("game_type")
|
||||
drawDate := r.FormValue("draw_date")
|
||||
drawDateStr := r.FormValue("draw_date")
|
||||
purchaseMethod := r.FormValue("purchase_method")
|
||||
purchaseDate := r.FormValue("purchase_date")
|
||||
purchaseTime := r.FormValue("purchase_time")
|
||||
|
||||
dt, err := helpers.ParseDrawDate(drawDateStr)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid draw date", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
drawDateDB := helpers.FormatDrawDate(dt) // "YYYY-MM-DD"
|
||||
|
||||
if purchaseTime != "" {
|
||||
purchaseDate += "T" + purchaseTime
|
||||
}
|
||||
@@ -165,7 +173,7 @@ func AddTicket(app *bootstrap.App) http.HandlerFunc {
|
||||
purchase_method, purchase_date, image_path
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
userID, game, drawDate,
|
||||
userID, game, drawDateDB,
|
||||
b[0], b[1], b[2], b[3], b[4], b[5],
|
||||
bo[0], bo[1],
|
||||
purchaseMethod, purchaseDate, imagePath,
|
||||
@@ -195,10 +203,18 @@ func SubmitTicket(app *bootstrap.App) http.HandlerFunc {
|
||||
}
|
||||
|
||||
game := r.FormValue("game_type")
|
||||
drawDate := r.FormValue("draw_date")
|
||||
drawDateStr := r.FormValue("draw_date")
|
||||
purchaseMethod := r.FormValue("purchase_method")
|
||||
purchaseDate := r.FormValue("purchase_date")
|
||||
purchaseTime := r.FormValue("purchase_time")
|
||||
|
||||
dt, err := helpers.ParseDrawDate(drawDateStr)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid draw date", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
drawDateDB := helpers.FormatDrawDate(dt)
|
||||
|
||||
if purchaseTime != "" {
|
||||
purchaseDate += "T" + purchaseTime
|
||||
}
|
||||
@@ -253,7 +269,7 @@ func SubmitTicket(app *bootstrap.App) http.HandlerFunc {
|
||||
purchase_method, purchase_date, image_path
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
userID, game, drawDate,
|
||||
userID, game, drawDateDB,
|
||||
b[0], b[1], b[2], b[3], b[4], b[5],
|
||||
bo[0], bo[1],
|
||||
purchaseMethod, purchaseDate, imagePath,
|
||||
@@ -299,6 +315,7 @@ func GetMyTickets(app *bootstrap.App) http.HandlerFunc {
|
||||
|
||||
for rows.Next() {
|
||||
var t models.Ticket
|
||||
var drawDateStr string // ← add
|
||||
var b1, b2, b3, b4, b5, b6, bo1, bo2 sql.NullInt64
|
||||
var matchedMain, matchedBonus sql.NullInt64
|
||||
var prizeTier sql.NullString
|
||||
@@ -307,7 +324,7 @@ func GetMyTickets(app *bootstrap.App) http.HandlerFunc {
|
||||
var prizeAmount sql.NullFloat64
|
||||
|
||||
if err := rows.Scan(
|
||||
&t.Id, &t.GameType, &t.DrawDate,
|
||||
&t.Id, &t.GameType, &drawDateStr, // ← was &t.DrawDate
|
||||
&b1, &b2, &b3, &b4, &b5, &b6,
|
||||
&bo1, &bo2,
|
||||
&t.PurchaseMethod, &t.PurchaseDate, &t.ImagePath, &t.Duplicate,
|
||||
@@ -317,6 +334,11 @@ func GetMyTickets(app *bootstrap.App) http.HandlerFunc {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse into time.Time (UTC)
|
||||
if dt, err := helpers.ParseDrawDate(drawDateStr); err == nil {
|
||||
t.DrawDate = dt
|
||||
}
|
||||
|
||||
// Normalize fields
|
||||
t.Ball1 = int(b1.Int64)
|
||||
t.Ball2 = int(b2.Int64)
|
||||
@@ -351,7 +373,7 @@ func GetMyTickets(app *bootstrap.App) http.HandlerFunc {
|
||||
t.BonusBalls = helpers.BuildBonusSlice(t)
|
||||
|
||||
// Fetch matching draw info
|
||||
draw := draws.GetDrawResultForTicket(app.DB, t.GameType, t.DrawDate)
|
||||
draw := draws.GetDrawResultForTicket(app.DB, t.GameType, helpers.FormatDrawDate(t.DrawDate))
|
||||
t.MatchedDraw = draw
|
||||
|
||||
tickets = append(tickets, t)
|
||||
|
||||
Reference in New Issue
Block a user