updated season league view page

This commit is contained in:
2026-02-14 21:08:00 +11:00
parent f9283c0563
commit 2944443143
23 changed files with 791 additions and 302 deletions

View File

@@ -77,6 +77,10 @@ func GetList[T any](tx bun.Tx) *listgetter[T] {
return l
}
func (l *listgetter[T]) String() string {
return l.q.String()
}
func (l *listgetter[T]) Join(join string, args ...any) *listgetter[T] {
l.q = l.q.Join(join, args...)
return l

View File

@@ -9,6 +9,22 @@ import (
"github.com/uptrace/bun"
)
// SeasonStatus represents the current status of a season
type SeasonStatus string
const (
// StatusUpcoming means the season has not started yet
StatusUpcoming SeasonStatus = "upcoming"
// StatusInProgress means the regular season is active
StatusInProgress SeasonStatus = "in_progress"
// StatusFinalsSoon means regular season ended, finals upcoming
StatusFinalsSoon SeasonStatus = "finals_soon"
// StatusFinals means finals are in progress
StatusFinals SeasonStatus = "finals"
// StatusCompleted means the season has finished
StatusCompleted SeasonStatus = "completed"
)
type Season struct {
bun.BaseModel `bun:"table:seasons,alias:s"`
@@ -107,6 +123,46 @@ type LeagueWithTeams struct {
Teams []*Team
}
// GetStatus returns the current status of the season based on dates
func (s *Season) GetStatus() SeasonStatus {
now := time.Now()
if now.Before(s.StartDate) {
return StatusUpcoming
}
if !s.FinalsStartDate.IsZero() {
if !s.FinalsEndDate.IsZero() && now.After(s.FinalsEndDate.Time) {
return StatusCompleted
}
if now.After(s.FinalsStartDate.Time) {
return StatusFinals
}
if !s.EndDate.IsZero() && now.After(s.EndDate.Time) {
return StatusFinalsSoon
}
return StatusInProgress
}
if !s.EndDate.IsZero() && now.After(s.EndDate.Time) {
return StatusCompleted
}
return StatusInProgress
}
// GetDefaultTab returns the default tab to show based on the season status
func (s *Season) GetDefaultTab() string {
switch s.GetStatus() {
case StatusInProgress:
return "table"
case StatusUpcoming:
return "teams"
default:
return "finals"
}
}
func (s *Season) HasLeague(leagueID int) bool {
for _, league := range s.Leagues {
if league.ID == leagueID {