Unassign handles POST /alerts/:id/unassign.
(w http.ResponseWriter, r *http.Request)
| 234 | |
| 235 | // Unassign handles POST /alerts/:id/unassign. |
| 236 | func (h *AlertsHandler) Unassign(w http.ResponseWriter, r *http.Request) { |
| 237 | id := chi.URLParam(r, "id") |
| 238 | if id == "" { |
| 239 | Error(w, http.StatusBadRequest, "Alert ID required") |
| 240 | return |
| 241 | } |
| 242 | if err := h.alerts.UpdateUnassign(r.Context(), id); err != nil { |
| 243 | Error(w, http.StatusInternalServerError, "Failed to unassign alert") |
| 244 | return |
| 245 | } |
| 246 | d := h.db.DB(r.Context()) |
| 247 | userID, _ := r.Context().Value(middleware.UserIDKey).(string) |
| 248 | var uid *string |
| 249 | if userID != "" { |
| 250 | uid = &userID |
| 251 | } |
| 252 | if err := h.alerts.RecordHistory(r.Context(), id, uid, "unassigned", map[string]interface{}{}); err != nil { |
| 253 | slog.Error("alerts: failed to record unassign history", "alert_id", id, "error", err) |
| 254 | } |
| 255 | if err := d.Queries.UpdateAlert(r.Context(), id); err != nil { |
| 256 | slog.Error("alerts: failed to update alert timestamp", "alert_id", id, "error", err) |
| 257 | } |
| 258 | |
| 259 | updated, _ := h.alerts.GetByID(r.Context(), id) |
| 260 | successData(w, updated) |
| 261 | } |
| 262 | |
| 263 | // Delete handles DELETE /alerts/:id. |
| 264 | func (h *AlertsHandler) Delete(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected