admin control features and admin dashboard

This commit is contained in:
ayurishchev committed 2026-08-23 20:39:22 +03:00
1 parent c630f13c57
commit 37910e410b
69 files changed
+4959 -400

No files matched your search

+17
View File
@@ -7,6 +7,7 @@ package httpapi
import (
"encoding/json"
"errors"
"log/slog"
"net/http"
@@ -56,3 +57,19 @@ func readJSON(r *http.Request, v interface{}) error {
dec := json.NewDecoder(r.Body)
return dec.Decode(v)
}
// writeDBError maps the typed sentinel errors returned by internal/db's
// admin mutation methods to the appropriate HTTP status, instead of
// defaulting everything to 500 like the older read-only admin handlers do.
func writeDBError(w http.ResponseWriter, err error) {
switch {
case errors.Is(err, db.ErrNotFound):
writeError(w, http.StatusNotFound, err.Error())
case errors.Is(err, db.ErrConflict), errors.Is(err, db.ErrBusy), errors.Is(err, db.ErrInUse), errors.Is(err, db.ErrInvalidState):
writeError(w, http.StatusConflict, err.Error())
case errors.Is(err, db.ErrValidation):
writeError(w, http.StatusBadRequest, err.Error())
default:
writeError(w, http.StatusInternalServerError, err.Error())
}
}