added leagues
This commit is contained in:
34
internal/handlers/leagues_list.go
Normal file
34
internal/handlers/leagues_list.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user