MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / Unassign

Method Unassign

server-source-code/internal/handler/alerts.go:236–261  ·  view source on GitHub ↗

Unassign handles POST /alerts/:id/unassign.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

234
235// Unassign handles POST /alerts/:id/unassign.
236func (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.
264func (h *AlertsHandler) Delete(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 9

ErrorFunction · 0.85
successDataFunction · 0.85
UpdateUnassignMethod · 0.80
RecordHistoryMethod · 0.80
ErrorMethod · 0.80
DBMethod · 0.65
UpdateAlertMethod · 0.65
ValueMethod · 0.45
GetByIDMethod · 0.45

Tested by

no test coverage detected