everybody loves a refactor

This commit is contained in:
2026-02-15 12:27:36 +11:00
parent 61890ae20b
commit ef8c022e60
44 changed files with 278 additions and 234 deletions

View File

@@ -6,6 +6,7 @@ import (
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/internal/respond"
"git.haelnorr.com/h/oslstats/internal/validation"
"github.com/pkg/errors"
"github.com/uptrace/bun"
@@ -20,7 +21,7 @@ func IsTeamShortNamesUnique(
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
getter, err := validation.ParseForm(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
respond.BadRequest(w, err)
return
}
@@ -28,12 +29,12 @@ func IsTeamShortNamesUnique(
altShortName := getter.String("alt_short_name").TrimSpace().ToUpper().MaxLength(3).Value
if shortName == "" || altShortName == "" {
w.WriteHeader(http.StatusOK)
respond.OK(w)
return
}
if shortName == altShortName {
w.WriteHeader(http.StatusConflict)
respond.Conflict(w, errors.New("short names cannot be the same"))
return
}
@@ -49,9 +50,9 @@ func IsTeamShortNamesUnique(
}
if isUnique {
w.WriteHeader(http.StatusOK)
respond.OK(w)
} else {
w.WriteHeader(http.StatusConflict)
respond.Conflict(w, errors.New("short name combination is taken"))
}
})
}