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

Method ListRuns

server-source-code/internal/handler/patching.go:459–510  ·  view source on GitHub ↗

ListRuns returns GET /patching/runs.

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

Source from the content-addressed store, hash-verified

457
458// ListRuns returns GET /patching/runs.
459func (h *PatchingHandler) ListRuns(w http.ResponseWriter, r *http.Request) {
460 limit := parseIntQuery(r, "limit", 50)
461 if limit < 1 {
462 limit = 1
463 }
464 if limit > 200 {
465 limit = 200
466 }
467 offset := parseIntQuery(r, "offset", 0)
468 if offset < 0 {
469 offset = 0
470 }
471 hostID := r.URL.Query().Get("host_id")
472 status := r.URL.Query().Get("status")
473 patchType := r.URL.Query().Get("patch_type")
474 sortBy := r.URL.Query().Get("sort_by")
475 sortDir := r.URL.Query().Get("sort_dir")
476 if hostID != "" && !isValidPatchUUID(hostID) {
477 hostID = ""
478 }
479 if patchType != "" && patchType != "patch_all" && patchType != "patch_package" {
480 patchType = ""
481 }
482 // Validate sort params
483 validSortBy := map[string]bool{"created_at": true, "started_at": true, "completed_at": true, "status": true}
484 if !validSortBy[sortBy] {
485 sortBy = "created_at"
486 }
487 if sortDir != "asc" && sortDir != "desc" {
488 sortDir = "desc"
489 }
490
491 runs, total, err := h.patchRuns.List(r.Context(), hostID, status, patchType, sortBy, sortDir, limit, offset)
492 if err != nil {
493 h.log.Error("patching: runs list error", "error", err)
494 JSON(w, http.StatusInternalServerError, map[string]string{"error": "Failed to load patch runs"})
495 return
496 }
497 pages := int(total) / limit
498 if int(total)%limit > 0 {
499 pages++
500 }
501 JSON(w, http.StatusOK, map[string]interface{}{
502 "runs": patchRunsListToResponse(runs),
503 "pagination": map[string]interface{}{
504 "total": total,
505 "limit": limit,
506 "offset": offset,
507 "pages": pages,
508 },
509 })
510}
511
512// GetRun returns GET /patching/runs/:id.
513func (h *PatchingHandler) GetRun(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 8

parseIntQueryFunction · 0.85
isValidPatchUUIDFunction · 0.85
patchRunsListToResponseFunction · 0.85
QueryMethod · 0.80
ErrorMethod · 0.80
JSONFunction · 0.70
GetMethod · 0.45
ListMethod · 0.45

Tested by

no test coverage detected