feat: add dashboard aggregation endpoint (Phase 2I)

GET /api/dashboard returns aggregated data:
- deadline_summary: overdue, due this/next week, ok counts
- case_summary: active, new this month, closed counts
- upcoming_deadlines: next 7 days with case info
- upcoming_appointments: next 7 days
- recent_activity: last 10 case events

Uses efficient CTE query for summaries. Also fixes duplicate
writeJSON/writeError declarations in appointments handler.
This commit is contained in:
m
2026-03-25 13:37:06 +01:00
parent 2c16f26448
commit e53e1389f9
5 changed files with 222 additions and 11 deletions

View File

@@ -27,6 +27,8 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
// Middleware
tenantResolver := auth.NewTenantResolver(tenantSvc)
dashboardSvc := services.NewDashboardService(db)
// Handlers
tenantH := handlers.NewTenantHandler(tenantSvc)
caseH := handlers.NewCaseHandler(caseSvc)
@@ -35,6 +37,7 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
deadlineH := handlers.NewDeadlineHandlers(deadlineSvc, db)
ruleH := handlers.NewDeadlineRuleHandlers(deadlineRuleSvc)
calcH := handlers.NewCalculateHandlers(calculator, deadlineRuleSvc)
dashboardH := handlers.NewDashboardHandler(dashboardSvc)
// Public routes
mux.HandleFunc("GET /health", handleHealth(db))
@@ -86,6 +89,9 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
scoped.HandleFunc("PUT /api/appointments/{id}", apptH.Update)
scoped.HandleFunc("DELETE /api/appointments/{id}", apptH.Delete)
// Dashboard
scoped.HandleFunc("GET /api/dashboard", dashboardH.Get)
// Placeholder routes for future phases
scoped.HandleFunc("GET /api/documents", placeholder("documents"))