updated season league view page

This commit is contained in:
2026-02-14 21:08:00 +11:00
parent f9283c0563
commit 2944443143
23 changed files with 791 additions and 302 deletions

View File

@@ -0,0 +1,60 @@
package handlers
import (
"context"
"net/http"
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/internal/throw"
seasonsview "git.haelnorr.com/h/oslstats/internal/view/seasonsview"
"github.com/pkg/errors"
"github.com/uptrace/bun"
)
// SeasonLeagueTeamsPage renders the teams tab of a season league page
func SeasonLeagueTeamsPage(
s *hws.Server,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seasonStr := r.PathValue("season_short_name")
leagueStr := r.PathValue("league_short_name")
var season *db.Season
var league *db.League
var teams []*db.Team
var available []*db.Team
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, teams, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
available, err = db.GetList[db.Team](tx).
Join("LEFT JOIN team_participations tp ON tp.team_id = t.id").
Where("NOT tp.season_id = ? OR tp.season_id IS NULL", season.ID).
GetAll(ctx)
if err != nil {
return false, errors.Wrap(err, "db.GetList[Team]")
}
return true, nil
}); !ok {
return
}
if season == nil || league == nil {
throw.NotFound(s, w, r, r.URL.Path)
return
}
if r.Method == "GET" {
renderSafely(seasonsview.SeasonLeagueTeamsPage(season, league, teams, available), s, r, w)
} else {
renderSafely(seasonsview.SeasonLeagueTeams(season, league, teams, available), s, r, w)
}
})
}