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

Method GetHistory

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

GetHistory handles GET /alerts/:id/history.

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

Source from the content-addressed store, hash-verified

94
95// GetHistory handles GET /alerts/:id/history.
96func (h *AlertsHandler) GetHistory(w http.ResponseWriter, r *http.Request) {
97 id := chi.URLParam(r, "id")
98 if id == "" {
99 Error(w, http.StatusBadRequest, "Alert ID required")
100 return
101 }
102 d := h.db.DB(r.Context())
103 rows, err := d.Queries.ListAlertHistoryByAlertID(r.Context(), id)
104 if err != nil {
105 Error(w, http.StatusInternalServerError, "Failed to fetch alert history")
106 return
107 }
108 out := make([]map[string]interface{}, len(rows))
109 for i, row := range rows {
110 u := map[string]interface{}{}
111 if row.UserIDVal != nil {
112 u["id"] = *row.UserIDVal
113 if row.Username != nil {
114 u["username"] = *row.Username
115 }
116 if row.Email != nil {
117 u["email"] = *row.Email
118 }
119 }
120 out[i] = map[string]interface{}{
121 "id": row.ID,
122 "alert_id": row.AlertID,
123 "user_id": row.UserID,
124 "action": row.Action,
125 "metadata": row.Metadata,
126 "created_at": row.CreatedAt.Time,
127 "user": u,
128 }
129 }
130 successData(w, out)
131}
132
133// PerformAction handles POST /alerts/:id/action.
134func (h *AlertsHandler) PerformAction(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 4

ErrorFunction · 0.85
successDataFunction · 0.85
DBMethod · 0.65

Tested by

no test coverage detected