big ole refactor

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

View File

@@ -6,7 +6,6 @@ import (
"net/http"
"git.haelnorr.com/h/golib/hws"
"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 NewSeason(
s *hws.Server,
conn *bun.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
renderSafely(seasonsview.NewPage(), s, r, w)
return
}
renderSafely(seasonsview.NewPage(), s, r, w)
})
}
func NewSeasonSubmit(
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)
@@ -58,7 +52,7 @@ func NewSeasonSubmit(
nameUnique := false
shortNameUnique := false
var season *db.Season
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.Season)(nil), "name", name)
if err != nil {
@@ -71,10 +65,9 @@ func NewSeasonSubmit(
if !nameUnique || !shortNameUnique {
return true, nil
}
season = db.NewSeason(name, version, shortname, start)
err = db.Insert(tx, season).WithAudit(r, audit.Callback()).Exec(ctx)
season, err = db.NewSeason(ctx, tx, name, version, shortname, start, db.NewAudit(r, nil))
if err != nil {
return false, errors.Wrap(err, "db.Insert")
return false, errors.Wrap(err, "db.NewSeason")
}
return true, nil
}); !ok {