Files
minstrel/internal/api/admin_coverage.go
T
bvandeusen a1d295ebac feat(server/m7-coverage-gauge): GET /api/admin/library/coverage
New admin handler returns the library-wide cover-art coverage rollup
{total, with_art, pending, settled, pending_no_mbid} for the admin
dashboard gauge. Always 200; zeros on empty library. Same RequireAdmin
middleware as /api/admin/scan/status. Lives under a new /library/
admin sub-namespace, parallel to /scan/ (per-run state) and /covers/
(actions).

Tests gated on MINSTREL_TEST_DATABASE_URL: empty library returns all
zeros, mixed rows produce correct bucket math (verifying the
with_art + pending + settled = total invariant), non-admin returns 403.
2026-05-06 09:54:56 -04:00

39 lines
1.2 KiB
Go

package api
import (
"net/http"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
)
// coverageRollupResp is the wire shape for GET /api/admin/library/coverage.
// All fields are non-negative counts. with_art + pending + settled = total;
// pending_no_mbid is a subset of pending.
type coverageRollupResp struct {
Total int64 `json:"total"`
WithArt int64 `json:"with_art"`
Pending int64 `json:"pending"`
Settled int64 `json:"settled"`
PendingNoMbid int64 `json:"pending_no_mbid"`
}
// handleGetLibraryCoverage implements GET /api/admin/library/coverage.
// Surfaces a library-wide rollup of albums.cover_art_source for the admin
// dashboard gauge. Always 200; zeros on an empty library.
func (h *handlers) handleGetLibraryCoverage(w http.ResponseWriter, r *http.Request) {
q := dbq.New(h.pool)
row, err := q.GetAlbumCoverageRollup(r.Context())
if err != nil {
h.logger.Error("admin: get coverage rollup", "err", err)
writeErr(w, http.StatusInternalServerError, "server_error", "lookup failed")
return
}
writeJSON(w, http.StatusOK, coverageRollupResp{
Total: row.Total,
WithArt: row.WithArt,
Pending: row.Pending,
Settled: row.Settled,
PendingNoMbid: row.PendingNoMbid,
})
}