added season edits
This commit is contained in:
@@ -59,3 +59,32 @@ func GetSeason(ctx context.Context, tx bun.Tx, shortname string) (*Season, error
|
||||
}
|
||||
return GetByField[Season](tx, "short_name", shortname).GetFirst(ctx)
|
||||
}
|
||||
|
||||
func UpdateSeason(ctx context.Context, tx bun.Tx, season *Season) error {
|
||||
if season == nil {
|
||||
return errors.New("season cannot be nil")
|
||||
}
|
||||
if season.ID == 0 {
|
||||
return errors.New("season ID cannot be 0")
|
||||
}
|
||||
// Truncate dates to day precision
|
||||
season.StartDate = season.StartDate.Truncate(time.Hour * 24)
|
||||
if !season.EndDate.IsZero() {
|
||||
season.EndDate.Time = season.EndDate.Time.Truncate(time.Hour * 24)
|
||||
}
|
||||
if !season.FinalsStartDate.IsZero() {
|
||||
season.FinalsStartDate.Time = season.FinalsStartDate.Time.Truncate(time.Hour * 24)
|
||||
}
|
||||
if !season.FinalsEndDate.IsZero() {
|
||||
season.FinalsEndDate.Time = season.FinalsEndDate.Time.Truncate(time.Hour * 24)
|
||||
}
|
||||
_, err := tx.NewUpdate().
|
||||
Model(season).
|
||||
Column("start_date", "end_date", "finals_start_date", "finals_end_date").
|
||||
Where("id = ?", season.ID).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tx.NewUpdate")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user