MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / Update

Method Update

server-source-code/internal/handler/metrics.go:72–104  ·  view source on GitHub ↗

Update handles PUT /api/v1/metrics - updates metrics_enabled.

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

Source from the content-addressed store, hash-verified

70
71// Update handles PUT /api/v1/metrics - updates metrics_enabled.
72func (h *MetricsHandler) Update(w http.ResponseWriter, r *http.Request) {
73 if h.adminModeGuard(w) {
74 return
75 }
76 var req struct {
77 MetricsEnabled *bool `json:"metrics_enabled"`
78 }
79 if err := decodeJSON(r, &req); err != nil {
80 Error(w, http.StatusBadRequest, "Invalid request body")
81 return
82 }
83 if req.MetricsEnabled == nil {
84 Error(w, http.StatusBadRequest, "metrics_enabled must be a boolean")
85 return
86 }
87
88 s, err := h.settings.GetFirst(r.Context())
89 if err != nil {
90 Error(w, http.StatusInternalServerError, "Failed to load settings")
91 return
92 }
93
94 s.MetricsEnabled = *req.MetricsEnabled
95 if err := h.settings.Update(r.Context(), s); err != nil {
96 Error(w, http.StatusInternalServerError, "Failed to update metrics settings")
97 return
98 }
99
100 JSON(w, http.StatusOK, map[string]interface{}{
101 "message": "Metrics settings updated successfully",
102 "metrics_enabled": s.MetricsEnabled,
103 })
104}
105
106// RegenerateID handles POST /api/v1/metrics/regenerate-id.
107func (h *MetricsHandler) RegenerateID(w http.ResponseWriter, r *http.Request) {

Callers 3

GetMethod · 0.45
RegenerateIDMethod · 0.45
SendNowMethod · 0.45

Calls 5

adminModeGuardMethod · 0.95
decodeJSONFunction · 0.85
ErrorFunction · 0.85
GetFirstMethod · 0.80
JSONFunction · 0.70

Tested by

no test coverage detected