diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-07 00:20:15 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-07 00:20:15 +0300 |
| commit | d87bcee585883f22b2ca0b42db67bf815cc7c1fc (patch) | |
| tree | a879c345d3ebaecf526f12d7ad6cf97c6f7f4dba /internal/api/handlers_admin.go | |
| parent | e1bea8d74391a20201327299481550bf94766236 (diff) | |
Task 51: add API error helpers
Diffstat (limited to 'internal/api/handlers_admin.go')
| -rw-r--r-- | internal/api/handlers_admin.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/internal/api/handlers_admin.go b/internal/api/handlers_admin.go index e9935d4..b1c3005 100644 --- a/internal/api/handlers_admin.go +++ b/internal/api/handlers_admin.go @@ -62,7 +62,7 @@ func (s *Server) handleCreateUser(w http.ResponseWriter, r *http.Request) { IsAdmin bool `json:"is_admin"` } if err := readJSON(r, &req); err != nil || req.Username == "" || req.Password == "" { - writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request"}) + badRequest(w, "invalid request") return } user, err := s.adminSvc.CreateUser(r.Context(), req.Username, req.Password, req.IsAdmin) @@ -80,7 +80,7 @@ func (s *Server) handleDeleteUser(w http.ResponseWriter, r *http.Request) { id := pathID(r, "id") adminUser, _ := r.Context().Value(userCtxKey).(*model.User) if adminUser != nil && adminUser.ID == id { - writeJSON(w, http.StatusBadRequest, map[string]string{"error": "cannot delete self"}) + badRequest(w, "cannot delete self") return } if err := s.adminSvc.DeleteUser(r.Context(), id); err != nil { @@ -112,7 +112,7 @@ func (s *Server) handleGrantPermission(w http.ResponseWriter, r *http.Request) { Role model.Role `json:"role"` } if err := readJSON(r, &req); err != nil { - writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request"}) + badRequest(w, "invalid request") return } if err := s.adminSvc.GrantPermission(r.Context(), req.SetID, req.UserID, req.Role); err != nil { @@ -131,7 +131,7 @@ func (s *Server) handleRevokePermission(w http.ResponseWriter, r *http.Request) UserID int64 `json:"user_id"` } if err := readJSON(r, &req); err != nil { - writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request"}) + badRequest(w, "invalid request") return } if err := s.adminSvc.RevokePermission(r.Context(), req.SetID, req.UserID); err != nil { |
