feat(dashboard): implement Phase 7 router registration and config setup

Add DashboardService and DashboardHandler to application configuration:

Router Config Updates (internal/router/router.go):
- Add services import for DashboardService type
- Add DashboardService field to Config struct
- DashboardService: Used by SSR routes in frontend.go for data fetching
- DashboardHandler: Used by API routes in dashboard.go for JSON endpoints

Server Initialization (cmd/server/main.go):
- Create dashboardService instance using services.NewDashboardService(queries)
- Keep dashboardHandler creation (already exists from Phase 4)
- Add DashboardService to routerConfig
- Both services now available for dependency injection

Test Helpers (cmd/server/tests/test_helpers.go):
- Create dashboardService instance for testing
- Create dashboardHandler instance for testing
- Add both DashboardService and DashboardHandler to routerConfig
- Ensures test environment matches production setup

Architecture Rationale:
- DashboardService: Service layer with business logic (reusable by SSR, mobile)
- DashboardHandler: HTTP handler layer (JSON API endpoints)
- Separation allows SSR templates to call service directly
- API routes use handler for proper HTTP response handling
- Mobile apps can use API endpoints via DashboardHandler

All three files updated consistently for complete integration.
This commit is contained in:
2026-02-19 21:06:23 -05:00
parent 9ef94efeb5
commit 380af685dc
3 changed files with 8 additions and 0 deletions
+2
View File
@@ -119,6 +119,7 @@ func main() {
// NEW: Create refactored handlers
collectionHandler := handlers.NewCollectionHandler(queries, connManager)
dashboardService := services.NewDashboardService(queries)
dashboardHandler := handlers.NewDashboardHandler(queries)
mediaHandler := handlers.NewMediaHandler(queries, libraryService, worker)
matchingHandler := handlers.NewMatchingHandler(queries, connManager)
@@ -170,6 +171,7 @@ func main() {
QueueHandler: queueHandler,
CollectionHandler: collectionHandler,
DashboardHandler: dashboardHandler,
DashboardService: dashboardService,
OPDSHandler: opdsHandler,
SystemSettingsHandler: systemSettingsHandler,
ConnManager: connManager,
+4
View File
@@ -411,6 +411,8 @@ func setupTestServer(t *testing.T) *TestServerSetup {
libraryService := services.NewLibraryService(queries)
worker := services.NewWorker(3)
collectionHandler := handlers.NewCollectionHandler(queries, connManager)
dashboardService := services.NewDashboardService(queries)
dashboardHandler := handlers.NewDashboardHandler(queries)
mediaHandler := handlers.NewMediaHandler(queries, libraryService, worker)
matchingHandler := handlers.NewMatchingHandler(queries, connManager)
@@ -451,6 +453,8 @@ func setupTestServer(t *testing.T) *TestServerSetup {
QueueHandler: queueHandler,
SystemSettingsHandler: systemSettingsHandler,
CollectionHandler: collectionHandler,
DashboardHandler: dashboardHandler,
DashboardService: dashboardService,
OPDSHandler: opdsHandler,
ConnManager: connManager,
QueueProcessor: queueProcessor,
+2
View File
@@ -6,6 +6,7 @@ import (
"bookhoard/internal/handlers"
"bookhoard/internal/middleware"
ratelimit "bookhoard/internal/middleware"
"bookhoard/internal/services"
"bookhoard/internal/sync"
"log"
"net/http"
@@ -48,6 +49,7 @@ type Config struct {
QueueHandler *handlers.QueueHandler
CollectionHandler *handlers.CollectionHandler
DashboardHandler *handlers.DashboardHandler
DashboardService *services.DashboardService
OPDSHandler *handlers.OPDSHandler
SystemSettingsHandler *handlers.SystemSettingsHandler
ConnManager *sync.ConnectionManager