package handlers import ( "context" "net/http" "git.haelnorr.com/h/golib/hws" "git.haelnorr.com/h/oslstats/internal/db" seasonsview "git.haelnorr.com/h/oslstats/internal/view/seasonsview" "github.com/pkg/errors" "github.com/uptrace/bun" ) func SeasonsPage( s *hws.Server, conn *bun.DB, ) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { pageOpts := pageOptsFromQuery(s, w, r) if pageOpts == nil { return } var seasons *db.List[db.Season] if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) { var err error seasons, err = db.ListSeasons(ctx, tx, pageOpts) if err != nil { return false, errors.Wrap(err, "db.ListSeasons") } return true, nil }); !ok { return } renderSafely(seasonsview.ListPage(seasons), s, r, w) }) } func SeasonsList( s *hws.Server, conn *bun.DB, ) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { pageOpts := pageOptsFromForm(s, w, r) if pageOpts == nil { return } var seasons *db.List[db.Season] if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) { var err error seasons, err = db.ListSeasons(ctx, tx, pageOpts) if err != nil { return false, errors.Wrap(err, "db.ListSeasons") } return true, nil }); !ok { return } renderSafely(seasonsview.SeasonsList(seasons), s, r, w) }) }