everybody loves a refactor

This commit is contained in:
2026-02-15 12:27:36 +11:00
parent 27915d0047
commit 51cb987269
44 changed files with 278 additions and 234 deletions

View File

@@ -23,28 +23,19 @@ func NewTeamParticipation(ctx context.Context, tx bun.Tx,
if err != nil {
return nil, nil, nil, errors.Wrap(err, "GetSeason")
}
if season == nil {
return nil, nil, nil, errors.New("season not found")
}
league, err := GetLeague(ctx, tx, leagueShortName)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "GetLeague")
}
if league == nil {
return nil, nil, nil, errors.New("league not found")
}
if !season.HasLeague(league.ID) {
return nil, nil, nil, errors.New("league is not assigned to the season")
return nil, nil, nil, BadRequestNotAssociated("season", "league", seasonShortName, leagueShortName)
}
team, err := GetTeam(ctx, tx, teamID)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "GetTeam")
}
if team == nil {
return nil, nil, nil, errors.New("team not found")
}
if team.InSeason(season.ID) {
return nil, nil, nil, errors.New("team already in season")
return nil, nil, nil, BadRequestAssociated("season", "team", seasonShortName, teamID)
}
participation := &TeamParticipation{
SeasonID: season.ID,