HandleDeleteAgent deletes an agent owned by the authenticated user.
(w http.ResponseWriter, r *http.Request)
| 610 | |
| 611 | // HandleDeleteAgent deletes an agent owned by the authenticated user. |
| 612 | func (ua *UserAuth) HandleDeleteAgent(w http.ResponseWriter, r *http.Request) { |
| 613 | user := ua.AuthenticateRequest(r) |
| 614 | if user == nil { |
| 615 | http.Error(w, "not authenticated", http.StatusUnauthorized) |
| 616 | return |
| 617 | } |
| 618 | |
| 619 | // Extract agent email from URL path |
| 620 | path := strings.TrimPrefix(r.URL.Path, "/api/dashboard/agents/") |
| 621 | email, _ := url.PathUnescape(path) |
| 622 | email = identity.NormalizeEmail(email) |
| 623 | if email == "" { |
| 624 | http.Error(w, "agent email required", http.StatusBadRequest) |
| 625 | return |
| 626 | } |
| 627 | |
| 628 | agent, err := ua.store.GetAgentByEmail(r.Context(), email) |
| 629 | if err != nil { |
| 630 | http.Error(w, "agent not found", http.StatusNotFound) |
| 631 | return |
| 632 | } |
| 633 | |
| 634 | if err := ua.store.DeleteAgent(r.Context(), agent.ID, user.ID); err != nil { |
| 635 | http.Error(w, err.Error(), http.StatusForbidden) |
| 636 | return |
| 637 | } |
| 638 | |
| 639 | w.WriteHeader(http.StatusOK) |
| 640 | } |
| 641 | |
| 642 | // HandleUpdateAgent updates an agent owned by the authenticated user. |
| 643 | func (ua *UserAuth) HandleUpdateAgent(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected