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

@@ -2,16 +2,17 @@ package handlers
import (
"context"
"fmt"
"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"
)
// SeasonLeaguePage redirects to the appropriate default tab based on season status
func SeasonLeaguePage(
s *hws.Server,
conn *db.DB,
@@ -22,22 +23,13 @@ func SeasonLeaguePage(
var season *db.Season
var league *db.League
var teams []*db.Team
var allTeams []*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)
season, league, _, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
// Get all teams for the dropdown (to add teams)
allTeams, err = db.GetList[db.Team](tx).GetAll(ctx)
if err != nil {
return false, errors.Wrap(err, "db.GetList[Team]")
}
return true, nil
}); !ok {
return
@@ -48,6 +40,11 @@ func SeasonLeaguePage(
return
}
renderSafely(seasonsview.SeasonLeaguePage(season, league, teams, allTeams), s, r, w)
defaultTab := season.GetDefaultTab()
redirectURL := fmt.Sprintf(
"/seasons/%s/leagues/%s/%s",
seasonStr, leagueStr, defaultTab,
)
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
})
}