added leagues
This commit is contained in:
@@ -19,14 +19,18 @@ type Season struct {
|
||||
EndDate bun.NullTime `bun:"end_date"`
|
||||
FinalsStartDate bun.NullTime `bun:"finals_start_date"`
|
||||
FinalsEndDate bun.NullTime `bun:"finals_end_date"`
|
||||
SlapVersion string `bun:"slap_version,notnull,default:'rebound'"`
|
||||
|
||||
Leagues []League `bun:"m2m:season_leagues,join:Season=League"`
|
||||
}
|
||||
|
||||
// NewSeason returns a new season. It does not add it to the database
|
||||
func NewSeason(name, shortname string, start time.Time) *Season {
|
||||
func NewSeason(name, version, shortname string, start time.Time) *Season {
|
||||
season := &Season{
|
||||
Name: name,
|
||||
ShortName: strings.ToUpper(shortname),
|
||||
StartDate: start.Truncate(time.Hour * 24),
|
||||
Name: name,
|
||||
ShortName: strings.ToUpper(shortname),
|
||||
StartDate: start.Truncate(time.Hour * 24),
|
||||
SlapVersion: version,
|
||||
}
|
||||
return season
|
||||
}
|
||||
@@ -38,18 +42,19 @@ func ListSeasons(ctx context.Context, tx bun.Tx, pageOpts *PageOpts) (*List[Seas
|
||||
bun.OrderDesc,
|
||||
"start_date",
|
||||
}
|
||||
return GetList[Season](tx).GetPaged(ctx, pageOpts, defaults)
|
||||
return GetList[Season](tx).Relation("Leagues").GetPaged(ctx, pageOpts, defaults)
|
||||
}
|
||||
|
||||
func GetSeason(ctx context.Context, tx bun.Tx, shortname string) (*Season, error) {
|
||||
if shortname == "" {
|
||||
return nil, errors.New("short_name not provided")
|
||||
}
|
||||
return GetByField[Season](tx, "short_name", shortname).Get(ctx)
|
||||
return GetByField[Season](tx, "short_name", shortname).Relation("Leagues").Get(ctx)
|
||||
}
|
||||
|
||||
// Update updates the season struct. It does not insert to the database
|
||||
func (s *Season) Update(start, end, finalsStart, finalsEnd time.Time) {
|
||||
func (s *Season) Update(version string, start, end, finalsStart, finalsEnd time.Time) {
|
||||
s.SlapVersion = version
|
||||
s.StartDate = start.Truncate(time.Hour * 24)
|
||||
if !end.IsZero() {
|
||||
s.EndDate.Time = end.Truncate(time.Hour * 24)
|
||||
|
||||
Reference in New Issue
Block a user