MCPcopy
hub / github.com/PatchMon/PatchMon / Assign

Method Assign

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

Assign handles POST /alerts/:id/assign.

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

Source from the content-addressed store, hash-verified

199
200// Assign handles POST /alerts/:id/assign.
201func (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.
236func (h *AlertsHandler) Unassign(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 10

ErrorFunction · 0.85
decodeJSONFunction · 0.85
successDataFunction · 0.85
UpdateAssignmentMethod · 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