Files
oslstats/internal/handlers/leagues_list.go
2026-02-10 23:32:48 +11:00

35 lines
738 B
Go

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