Files
archivdms/internal/api/dashboard_handlers.go
T
patrick 89de794356
CI / Backend (go vet, go test -cover) (push) Has been cancelled
CI / Frontend (ESLint, tsc, next build) (push) Has been cancelled
FDN-02/FDN-03/FDN-07/FDN-08: Migrations-Rollback, Objekt-Storage-Interface, go.sum-Fix, Observability
- FDN-02: Rollback-fähige Down-Migrationen (024-026), archivdms seed dev CLI
- FDN-03: internal/objectstore Interface + lokaler WORM-Treiber, signierte Download-URLs
- FDN-07: go.mod/go.sum vervollständigt (fehlender go-ldap/v3-Eintrag), CI-Pipeline (.gitea/workflows/ci.yml, bereits in FDN-01 committet) damit lauffähig
- FDN-08: Request-ID-Middleware, /metrics-Endpoint, Panic-Recovery, Login/Logout/Me technisches Logging inkl. Access-Log je Anfrage
2026-08-11 22:27:52 +02:00

30 lines
995 B
Go

package api
import (
"net/http"
"archivdms/internal/storage"
)
// handleDashboard returns aggregated, tenant-scoped key figures for the
// dashboard (GET /api/dashboard). Any authenticated user may view their own
// tenant's stats — no admin role required. Read-only, so no audit-log entry.
// Superadmin accounts have no tenant_id (by design, see auth.Manager.issueToken);
// they get an empty/zeroed snapshot instead of a 403, since there is no
// single tenant to scope the query to.
func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
sess := sessionFromCtx(r.Context())
if sess.TenantID == nil {
writeJSON(w, http.StatusOK, &storage.DashboardStats{})
return
}
stats, err := s.store.GetDashboardStats(r.Context(), *sess.TenantID, sess.UserID)
if err != nil {
s.reqLog(r.Context()).Error("dashboard stats failed", "err", err)
writeError(w, http.StatusInternalServerError, "dashboard stats failed")
return
}
writeJSON(w, http.StatusOK, stats)
}