Lots of changes around viewing tickets from css perspective logic changes nwe handlers and service triggers... just lots of stuff...

This commit is contained in:
2025-03-28 10:05:54 +00:00
parent e13b375af7
commit 23e0208317
22 changed files with 410 additions and 148 deletions

22
helpers/ballslice.go Normal file
View File

@@ -0,0 +1,22 @@
package helpers
import "synlotto-website/models"
func BuildBallsSlice(t models.Ticket) []int {
balls := []int{t.Ball1, t.Ball2, t.Ball3, t.Ball4, t.Ball5}
if t.GameType == "Lotto" && t.Ball6 > 0 {
balls = append(balls, t.Ball6)
}
return balls
}
func BuildBonusSlice(t models.Ticket) []int {
var bonuses []int
if t.Bonus1 != nil {
bonuses = append(bonuses, *t.Bonus1)
}
if t.Bonus2 != nil {
bonuses = append(bonuses, *t.Bonus2)
}
return bonuses
}

13
helpers/intptr.go Normal file
View File

@@ -0,0 +1,13 @@
package helpers
import (
"database/sql"
)
func IntPtrIfValid(val sql.NullInt64) *int {
if val.Valid {
n := int(val.Int64)
return &n
}
return nil
}

View File

@@ -4,6 +4,8 @@ import (
"html/template"
"net/http"
"synlotto-website/models"
"github.com/gorilla/csrf"
)
func TemplateFuncs() template.FuncMap {
@@ -29,6 +31,7 @@ func TemplateFuncs() template.FuncMap {
}
return *p
},
"inSlice": InSlice,
}
}
@@ -54,7 +57,17 @@ func TemplateContext(w http.ResponseWriter, r *http.Request) map[string]interfac
}
return map[string]interface{}{
"Flash": flash,
"User": currentUser,
"CSRFField": csrf.TemplateField(r),
"Flash": flash,
"User": currentUser,
}
}
func InSlice(n int, list []int) bool {
for _, v := range list {
if v == n {
return true
}
}
return false
}