Rewrites the internal/api comment blocks to rule 32: task, milestone and rule ids gone, the stories behind them restated as the constraint they left, stale references corrected (the stream secret is wired from config, the timezone handler already refreshes the scheduler, the Android app is the native client, the design docs cited are not in the repo). Also rewraps comment lines over 80 columns left by the earlier batches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
)
|
|
|
|
// adminQueueView is one queue that waits on a person: how many, and since
|
|
// when the oldest of them has waited (null when the queue is empty).
|
|
type adminQueueView struct {
|
|
Count int64 `json:"count"`
|
|
Since *string `json:"since"`
|
|
}
|
|
|
|
// adminSummaryView is what the admin rail and the Overview's verdict read:
|
|
// every queue an admin acts on, in one response, so each admin page pays one
|
|
// cheap read for its rail.
|
|
type adminSummaryView struct {
|
|
Requests adminQueueView `json:"requests"`
|
|
Reports adminQueueView `json:"reports"`
|
|
Duplicates adminQueueView `json:"duplicates"`
|
|
Suspect adminQueueView `json:"suspect"`
|
|
Missing adminQueueView `json:"missing"`
|
|
}
|
|
|
|
func queueView(count int64, since pgtype.Timestamptz) adminQueueView {
|
|
v := adminQueueView{Count: count}
|
|
if count > 0 && since.Valid {
|
|
s := formatTimestamp(since)
|
|
v.Since = &s
|
|
}
|
|
return v
|
|
}
|
|
|
|
func adminSummaryFrom(row dbq.AdminSummaryRow) adminSummaryView {
|
|
return adminSummaryView{
|
|
Requests: queueView(row.Requests, row.RequestsSince),
|
|
Reports: queueView(row.Reports, row.ReportsSince),
|
|
Duplicates: queueView(row.Duplicates, row.DuplicatesSince),
|
|
Suspect: queueView(row.Suspect, row.SuspectSince),
|
|
Missing: queueView(row.Missing, row.MissingSince),
|
|
}
|
|
}
|
|
|
|
// handleGetAdminSummary implements GET /api/admin/summary.
|
|
func (h *handlers) handleGetAdminSummary(w http.ResponseWriter, r *http.Request) {
|
|
row, err := dbq.New(h.pool).AdminSummary(r.Context())
|
|
if err != nil {
|
|
h.logger.Error("admin: summary", "err", err)
|
|
writeAdminJSONErr(w, http.StatusInternalServerError, "server_error")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, adminSummaryFrom(row))
|
|
}
|