big ole refactor

This commit is contained in:
2026-02-14 19:48:59 +11:00
parent f0e7962af5
commit 8a79533de3
66 changed files with 989 additions and 1114 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/uptrace/bun"
"git.haelnorr.com/h/oslstats/internal/auditlog"
"git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/internal/notify"
"git.haelnorr.com/h/oslstats/internal/validation"
@@ -18,20 +17,15 @@ import (
func NewLeague(
s *hws.Server,
conn *bun.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
renderSafely(leaguesview.NewPage(), s, r, w)
return
}
renderSafely(leaguesview.NewPage(), s, r, w)
})
}
func NewLeagueSubmit(
s *hws.Server,
conn *bun.DB,
audit *auditlog.Logger,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
getter, ok := validation.ParseFormOrNotify(s, w, r)
@@ -53,7 +47,7 @@ func NewLeagueSubmit(
nameUnique := false
shortNameUnique := false
var league *db.League
if ok := db.WithNotifyTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
if ok := conn.WithNotifyTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
nameUnique, err = db.IsUnique(ctx, tx, (*db.League)(nil), "name", name)
if err != nil {
@@ -66,14 +60,9 @@ func NewLeagueSubmit(
if !nameUnique || !shortNameUnique {
return true, nil
}
league = &db.League{
Name: name,
ShortName: shortname,
Description: description,
}
err = db.Insert(tx, league).WithAudit(r, audit.Callback()).Exec(ctx)
league, err = db.NewLeague(ctx, tx, name, shortname, description, db.NewAudit(r, nil))
if err != nil {
return false, errors.Wrap(err, "db.Insert")
return false, errors.Wrap(err, "db.NewLeague")
}
return true, nil
}); !ok {