big ole refactor
This commit is contained in:
@@ -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/throw"
|
||||
@@ -19,13 +18,13 @@ import (
|
||||
|
||||
func SeasonEditPage(
|
||||
s *hws.Server,
|
||||
conn *bun.DB,
|
||||
conn *db.DB,
|
||||
) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seasonStr := r.PathValue("season_short_name")
|
||||
var season *db.Season
|
||||
var allLeagues []*db.League
|
||||
if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
var err error
|
||||
season, err = db.GetSeason(ctx, tx, seasonStr)
|
||||
if err != nil {
|
||||
@@ -49,8 +48,7 @@ func SeasonEditPage(
|
||||
|
||||
func SeasonEditSubmit(
|
||||
s *hws.Server,
|
||||
conn *bun.DB,
|
||||
audit *auditlog.Logger,
|
||||
conn *db.DB,
|
||||
) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seasonStr := r.PathValue("season_short_name")
|
||||
@@ -77,7 +75,7 @@ func SeasonEditSubmit(
|
||||
}
|
||||
|
||||
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
|
||||
season, err = db.GetSeason(ctx, tx, seasonStr)
|
||||
if err != nil {
|
||||
@@ -86,12 +84,9 @@ func SeasonEditSubmit(
|
||||
if season == nil {
|
||||
return false, errors.New("season does not exist")
|
||||
}
|
||||
season.Update(version, start, end, finalsStart, finalsEnd)
|
||||
err = db.Update(tx, season).WherePK().
|
||||
Column("slap_version", "start_date", "end_date", "finals_start_date", "finals_end_date").
|
||||
WithAudit(r, audit.Callback()).Exec(ctx)
|
||||
err = season.Update(ctx, tx, version, start, end, finalsStart, finalsEnd, db.NewAudit(r, nil))
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "db.Update")
|
||||
return false, errors.Wrap(err, "season.Update")
|
||||
}
|
||||
return true, nil
|
||||
}); !ok {
|
||||
|
||||
Reference in New Issue
Block a user