Assign handles POST /alerts/:id/assign.
(w http.ResponseWriter, r *http.Request)
| 199 | |
| 200 | // Assign handles POST /alerts/:id/assign. |
| 201 | func (h *AlertsHandler) Assign(w http.ResponseWriter, r *http.Request) { |
| 202 | id := chi.URLParam(r, "id") |
| 203 | if id == "" { |
| 204 | Error(w, http.StatusBadRequest, "Alert ID required") |
| 205 | return |
| 206 | } |
| 207 | var req struct { |
| 208 | UserID string `json:"userId"` |
| 209 | } |
| 210 | if err := decodeJSON(r, &req); err != nil || req.UserID == "" { |
| 211 | Error(w, http.StatusBadRequest, "userId required") |
| 212 | return |
| 213 | } |
| 214 | if err := h.alerts.UpdateAssignment(r.Context(), id, req.UserID); err != nil { |
| 215 | Error(w, http.StatusInternalServerError, "Failed to assign alert") |
| 216 | return |
| 217 | } |
| 218 | d := h.db.DB(r.Context()) |
| 219 | userID, _ := r.Context().Value(middleware.UserIDKey).(string) |
| 220 | var uid *string |
| 221 | if userID != "" { |
| 222 | uid = &userID |
| 223 | } |
| 224 | if err := h.alerts.RecordHistory(r.Context(), id, uid, "assigned", map[string]interface{}{"assigned_to": req.UserID}); err != nil { |
| 225 | slog.Error("alerts: failed to record assign history", "alert_id", id, "error", err) |
| 226 | } |
| 227 | if err := d.Queries.UpdateAlert(r.Context(), id); err != nil { |
| 228 | slog.Error("alerts: failed to update alert timestamp", "alert_id", id, "error", err) |
| 229 | } |
| 230 | |
| 231 | updated, _ := h.alerts.GetByID(r.Context(), id) |
| 232 | successData(w, updated) |
| 233 | } |
| 234 | |
| 235 | // Unassign handles POST /alerts/:id/unassign. |
| 236 | func (h *AlertsHandler) Unassign(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected