From 1eefc6fc815e5fbd781e8818c61aa024821ce0d3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 10 May 2026 09:59:21 +0300 Subject: Move self-deletion guard from handler into AdminService (DeleteUser) to fix SoC violation - Add ErrCannotDeleteSelf sentinel error in service layer. - Change DeleteUser signature to (ctx, callerID, id) across all layers. - Move self-deletion guard from handleDeleteUser handler into userAdminService.DeleteUser. - Update handleError to map ErrCannotDeleteSelf to 400 BadRequest. - Adjust all affected tests to use the new signature. --- internal/api/handlers_admin.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'internal/api/handlers_admin.go') diff --git a/internal/api/handlers_admin.go b/internal/api/handlers_admin.go index 6d10c67..d68b07c 100644 --- a/internal/api/handlers_admin.go +++ b/internal/api/handlers_admin.go @@ -83,11 +83,11 @@ func (s *Server) handleDeleteUser(w http.ResponseWriter, r *http.Request) { return } adminUser, _ := r.Context().Value(userCtxKey).(*model.User) - if adminUser != nil && adminUser.ID == id { - badRequest(w, "cannot delete self") - return + var callerID int64 + if adminUser != nil { + callerID = adminUser.ID } - if err := s.adminSvc.DeleteUser(r.Context(), id); err != nil { + if err := s.adminSvc.DeleteUser(r.Context(), callerID, id); err != nil { handleError(w, err) return } -- cgit v1.2.3