package handlers import ( "context" "net/http" "git.haelnorr.com/h/golib/hws" "git.haelnorr.com/h/oslstats/internal/db" teamsview "git.haelnorr.com/h/oslstats/internal/view/teamsview" "github.com/pkg/errors" "github.com/uptrace/bun" ) // TeamsPage renders the full page with the teams list, for use with GET requests func TeamsPage( s *hws.Server, conn *db.DB, ) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { pageOpts, ok := db.GetPageOpts(s, w, r) if !ok { return } var teams *db.List[db.Team] if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) { var err error teams, err = db.ListTeams(ctx, tx, pageOpts) if err != nil { return false, errors.Wrap(err, "db.ListTeams") } return true, nil }); !ok { return } if r.Method == "GET" { renderSafely(teamsview.ListPage(teams), s, r, w) } else { renderSafely(teamsview.TeamsList(teams), s, r, w) } }) }