updated season league view page
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user