fix some stuff

main
DustyP 9 months ago
parent edc8a378a9
commit 9423d2cf88

@ -6,6 +6,7 @@ import (
"log/slog"
"os"
"path/filepath"
"track-gopher/models"
_ "github.com/mattn/go-sqlite3"
)
@ -141,36 +142,8 @@ func (db *DB) Close() error {
return db.DB.Close()
}
// Group represents a group of racers
type Group struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
// Racer represents a racer in the derby
type Racer struct {
ID int64 `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
CarNumber string `json:"car_number"`
CarWeight float64 `json:"car_weight"`
GroupID int64 `json:"group_id"`
}
// Heat represents a single race with 4 lanes
type Heat struct {
ID int64 `json:"id"`
GroupID int64 `json:"group_id"`
HeatNum int `json:"heat_num"`
Lane1ID *int64 `json:"lane1_id"`
Lane2ID *int64 `json:"lane2_id"`
Lane3ID *int64 `json:"lane3_id"`
Lane4ID *int64 `json:"lane4_id"`
}
// SaveHeats saves a list of heats for a group
func (db *DB) SaveHeats(groupID int64, heats []Heat) error {
func (db *DB) SaveHeats(groupID int64, heats []models.Heat) error {
// Start a transaction
tx, err := db.Begin()
if err != nil {
@ -221,7 +194,7 @@ func nullableInt64(i *int64) interface{} {
}
// GetHeats retrieves all heats for a group
func (db *DB) GetHeats(groupID int64) ([]Heat, error) {
func (db *DB) GetHeats(groupID int64) ([]models.Heat, error) {
rows, err := db.Query(`
SELECT id, group_id, heat_num, lane1_id, lane2_id, lane3_id, lane4_id
FROM heats
@ -233,9 +206,9 @@ func (db *DB) GetHeats(groupID int64) ([]Heat, error) {
}
defer rows.Close()
var heats []Heat
var heats []models.Heat
for rows.Next() {
var heat Heat
var heat models.Heat
var lane1, lane2, lane3, lane4 sql.NullInt64
err := rows.Scan(

@ -42,3 +42,14 @@ type RaceResult struct {
Place *int `json:"place,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
// Heat represents a single race with 4 lanes
type Heat struct {
ID int64 `json:"id"`
GroupID int64 `json:"group_id"`
HeatNum int `json:"heat_num"`
Lane1ID *int64 `json:"lane1_id"`
Lane2ID *int64 `json:"lane2_id"`
Lane3ID *int64 `json:"lane3_id"`
Lane4ID *int64 `json:"lane4_id"`
}

@ -20,6 +20,7 @@ import (
"track-gopher/db"
"track-gopher/derby"
"track-gopher/models"
"track-gopher/web/templates"
)
@ -724,7 +725,7 @@ func (s *Server) handleGenerateHeats() http.HandlerFunc {
}
// Filter racers by group
var groupRacers []db.Racer
var groupRacers []models.Racer
for _, racer := range allRacers {
if racer.GroupID == groupID {
groupRacers = append(groupRacers, racer)
@ -771,7 +772,7 @@ func (s *Server) handleSaveHeats() http.HandlerFunc {
}
// Filter racers by group
var groupRacers []db.Racer
var groupRacers []models.Racer
for _, racer := range allRacers {
if racer.GroupID == groupID {
groupRacers = append(groupRacers, racer)
@ -793,9 +794,9 @@ func (s *Server) handleSaveHeats() http.HandlerFunc {
derbyHeats := derby.GenerateHeats(derbyRacers)
// Convert to database heats
dbHeats := make([]db.Heat, len(derbyHeats))
dbHeats := make([]models.Heat, len(derbyHeats))
for i, heat := range derbyHeats {
dbHeats[i] = db.Heat{
dbHeats[i] = models.Heat{
GroupID: groupID,
HeatNum: heat.HeatNum,
Lane1ID: heat.Lane1ID,

@ -2,11 +2,10 @@ package templates
import (
"strconv"
"track-gopher/db"
"track-gopher/derby"
"track-gopher/models"
)
templ Heats(groups []db.Group, racers []db.Racer, selectedGroupID int64) {
templ Heats(groups []models.Group, racers []models.Racer, selectedGroupID int64) {
@Layout("Race Heats") {
<div class="container mx-auto px-4 py-8">
<h1 class="text-3xl font-bold mb-6">Race Heats Generator</h1>
@ -44,9 +43,9 @@ templ Heats(groups []db.Group, racers []db.Racer, selectedGroupID int64) {
}
}
templ HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) {
templ HeatsContent(groupID int64, groups []models.Group, allRacers []models.Racer) {
// Filter racers by group
var groupRacers []db.Racer
var groupRacers []models.Racer
for _, racer := range allRacers {
if racer.GroupID == groupID {
groupRacers = append(groupRacers, racer)
@ -91,7 +90,7 @@ templ HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) {
</div>
}
templ GeneratedHeats(racers []db.Racer) {
templ GeneratedHeats(racers []models.Racer) {
// Convert db.Racer to derby.Racer for heat generation
var derbyRacers []derby.Racer
for _, racer := range racers {
@ -146,7 +145,7 @@ templ GeneratedHeats(racers []db.Racer) {
}
}
func getGroupName(groups []db.Group, groupID int64) string {
func getGroupName(groups []models.Group, groupID int64) string {
for _, group := range groups {
if group.ID == groupID {
return group.Name
@ -155,7 +154,7 @@ func getGroupName(groups []db.Group, groupID int64) string {
return "Unknown Group"
}
func getRacerName(racers []db.Racer, racerID *int64) string {
func getRacerName(racers []models.Racer, racerID *int64) string {
if racerID == nil {
return "Empty"
}
@ -168,7 +167,7 @@ func getRacerName(racers []db.Racer, racerID *int64) string {
return "Unknown Racer"
}
func getRacerCarNumber(racers []db.Racer, racerID *int64) string {
func getRacerCarNumber(racers []models.Racer, racerID *int64) string {
if racerID == nil {
return "-"
}

@ -10,11 +10,10 @@ import templruntime "github.com/a-h/templ/runtime"
import (
"strconv"
"track-gopher/db"
"track-gopher/derby"
"track-gopher/models"
)
func Heats(groups []db.Group, racers []db.Racer, selectedGroupID int64) templ.Component {
func Heats(groups []models.Group, racers []models.Racer, selectedGroupID int64) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@ -59,7 +58,7 @@ func Heats(groups []db.Group, racers []db.Racer, selectedGroupID int64) templ.Co
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(group.ID, 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 27, Col: 53}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 26, Col: 53}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
@ -82,7 +81,7 @@ func Heats(groups []db.Group, racers []db.Racer, selectedGroupID int64) templ.Co
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(group.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 28, Col: 19}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 27, Col: 19}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
@ -122,7 +121,7 @@ func Heats(groups []db.Group, racers []db.Racer, selectedGroupID int64) templ.Co
})
}
func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.Component {
func HeatsContent(groupID int64, groups []models.Group, allRacers []models.Racer) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@ -143,7 +142,7 @@ func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.
templ_7745c5c3_Var5 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "var groupRacers []db.Racer ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "var groupRacers []models.Racer ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -162,7 +161,7 @@ func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(getGroupName(groups, groupID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 59, Col: 45}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 58, Col: 45}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
@ -175,7 +174,7 @@ func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(len(groupRacers)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 59, Col: 81}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 58, Col: 81}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
@ -188,7 +187,7 @@ func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs("/api/heats/generate?group_id=" + strconv.FormatInt(groupID, 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 64, Col: 79}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 63, Col: 79}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
@ -201,7 +200,7 @@ func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs("/api/heats/save?group_id=" + strconv.FormatInt(groupID, 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 72, Col: 75}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 71, Col: 75}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@ -238,7 +237,7 @@ func HeatsContent(groupID int64, groups []db.Group, allRacers []db.Racer) templ.
})
}
func GeneratedHeats(racers []db.Racer) templ.Component {
func GeneratedHeats(racers []models.Racer) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@ -291,7 +290,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(heat.HeatNum))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 111, Col: 77}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 110, Col: 77}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
@ -304,7 +303,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerName(racers, heat.Lane1ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 123, Col: 66}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 122, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
@ -317,7 +316,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerCarNumber(racers, heat.Lane1ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 124, Col: 71}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 123, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
@ -330,7 +329,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerName(racers, heat.Lane2ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 128, Col: 66}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 127, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
@ -343,7 +342,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerCarNumber(racers, heat.Lane2ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 129, Col: 71}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 128, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
@ -356,7 +355,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerName(racers, heat.Lane3ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 133, Col: 66}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 132, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
@ -369,7 +368,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerCarNumber(racers, heat.Lane3ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 134, Col: 71}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 133, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
@ -382,7 +381,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var18 string
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerName(racers, heat.Lane4ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 138, Col: 66}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 137, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
if templ_7745c5c3_Err != nil {
@ -395,7 +394,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
var templ_7745c5c3_Var19 string
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(getRacerCarNumber(racers, heat.Lane4ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 139, Col: 71}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/heats.templ`, Line: 138, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
if templ_7745c5c3_Err != nil {
@ -415,7 +414,7 @@ func GeneratedHeats(racers []db.Racer) templ.Component {
})
}
func getGroupName(groups []db.Group, groupID int64) string {
func getGroupName(groups []models.Group, groupID int64) string {
for _, group := range groups {
if group.ID == groupID {
return group.Name
@ -424,7 +423,7 @@ func getGroupName(groups []db.Group, groupID int64) string {
return "Unknown Group"
}
func getRacerName(racers []db.Racer, racerID *int64) string {
func getRacerName(racers []models.Racer, racerID *int64) string {
if racerID == nil {
return "Empty"
}
@ -437,7 +436,7 @@ func getRacerName(racers []db.Racer, racerID *int64) string {
return "Unknown Racer"
}
func getRacerCarNumber(racers []db.Racer, racerID *int64) string {
func getRacerCarNumber(racers []models.Racer, racerID *int64) string {
if racerID == nil {
return "-"
}

Loading…
Cancel
Save