Git-Repository für bestehenden archivdms-Code initialisiert, Branch-/Commit-Konvention (feature/<ticket>-<slug>-Branches, Ticket-Prefix in Commit-Nachricht) etabliert.
30 lines
982 B
Go
30 lines
982 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.logger.Error("dashboard stats failed", "err", err)
|
|
writeError(w, http.StatusInternalServerError, "dashboard stats failed")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, stats)
|
|
}
|