big ole refactor
This commit is contained in:
@@ -25,15 +25,22 @@ type Season struct {
|
||||
Teams []Team `bun:"m2m:team_participations,join:Season=Team"`
|
||||
}
|
||||
|
||||
// NewSeason returns a new season. It does not add it to the database
|
||||
func NewSeason(name, version, shortname string, start time.Time) *Season {
|
||||
// NewSeason creats a new season
|
||||
func NewSeason(ctx context.Context, tx bun.Tx, name, version, shortname string,
|
||||
start time.Time, audit *AuditMeta,
|
||||
) (*Season, error) {
|
||||
season := &Season{
|
||||
Name: name,
|
||||
ShortName: strings.ToUpper(shortname),
|
||||
StartDate: start.Truncate(time.Hour * 24),
|
||||
SlapVersion: version,
|
||||
}
|
||||
return season
|
||||
err := Insert(tx, season).
|
||||
WithAudit(audit, nil).Exec(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "db.Insert")
|
||||
}
|
||||
return season, nil
|
||||
}
|
||||
|
||||
func ListSeasons(ctx context.Context, tx bun.Tx, pageOpts *PageOpts) (*List[Season], error) {
|
||||
@@ -54,7 +61,9 @@ func GetSeason(ctx context.Context, tx bun.Tx, shortname string) (*Season, error
|
||||
}
|
||||
|
||||
// Update updates the season struct. It does not insert to the database
|
||||
func (s *Season) Update(version string, start, end, finalsStart, finalsEnd time.Time) {
|
||||
func (s *Season) Update(ctx context.Context, tx bun.Tx, version string,
|
||||
start, end, finalsStart, finalsEnd time.Time, audit *AuditMeta,
|
||||
) error {
|
||||
s.SlapVersion = version
|
||||
s.StartDate = start.Truncate(time.Hour * 24)
|
||||
if !end.IsZero() {
|
||||
@@ -66,6 +75,9 @@ func (s *Season) Update(version string, start, end, finalsStart, finalsEnd time.
|
||||
if !finalsEnd.IsZero() {
|
||||
s.FinalsEndDate.Time = finalsEnd.Truncate(time.Hour * 24)
|
||||
}
|
||||
return Update(tx, s).WherePK().
|
||||
Column("slap_version", "start_date", "end_date", "finals_start_date", "finals_end_date").
|
||||
WithAudit(audit, nil).Exec(ctx)
|
||||
}
|
||||
|
||||
func (s *Season) MapTeamsToLeagues(ctx context.Context, tx bun.Tx) ([]LeagueWithTeams, error) {
|
||||
|
||||
Reference in New Issue
Block a user