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:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user