added season types and changed new season to be a modal
This commit is contained in:
@@ -25,6 +25,17 @@ const (
|
||||
StatusCompleted SeasonStatus = "completed"
|
||||
)
|
||||
|
||||
type SeasonType string
|
||||
|
||||
func (s SeasonType) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
const (
|
||||
SeasonTypeRegular SeasonType = "regular"
|
||||
SeasonTypeDraft SeasonType = "draft"
|
||||
)
|
||||
|
||||
type Season struct {
|
||||
bun.BaseModel `bun:"table:seasons,alias:s"`
|
||||
|
||||
@@ -36,13 +47,14 @@ type Season struct {
|
||||
FinalsStartDate bun.NullTime `bun:"finals_start_date" json:"finals_start_date"`
|
||||
FinalsEndDate bun.NullTime `bun:"finals_end_date" json:"finals_end_date"`
|
||||
SlapVersion string `bun:"slap_version,notnull,default:'rebound'" json:"slap_version"`
|
||||
Type string `bun:"type,notnull" json:"type"`
|
||||
|
||||
Leagues []League `bun:"m2m:season_leagues,join:Season=League" json:"-"`
|
||||
Teams []Team `bun:"m2m:team_participations,join:Season=Team" json:"-"`
|
||||
}
|
||||
|
||||
// NewSeason creats a new season
|
||||
func NewSeason(ctx context.Context, tx bun.Tx, name, version, shortname string,
|
||||
func NewSeason(ctx context.Context, tx bun.Tx, name, version, shortname, type_ string,
|
||||
start time.Time, audit *AuditMeta,
|
||||
) (*Season, error) {
|
||||
season := &Season{
|
||||
@@ -50,12 +62,19 @@ func NewSeason(ctx context.Context, tx bun.Tx, name, version, shortname string,
|
||||
ShortName: strings.ToUpper(shortname),
|
||||
StartDate: start.Truncate(time.Hour * 24),
|
||||
SlapVersion: version,
|
||||
Type: type_,
|
||||
}
|
||||
err := Insert(tx, season).
|
||||
WithAudit(audit, nil).Exec(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "db.Insert")
|
||||
}
|
||||
if season.Type == SeasonTypeDraft.String() {
|
||||
err = NewSeasonLeague(ctx, tx, season.ShortName, "Draft", audit)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NewSeasonLeague")
|
||||
}
|
||||
}
|
||||
return season, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user