From 1be4ea24f2c851a74ff5013ac8da957d9706c948 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 7 Feb 2026 19:49:07 -0500 Subject: [PATCH] refactor(handlers): Phase 1 - simplify SetupRoutes to factory function - Remove all route registration from SetupRoutes - Make SetupRoutes a pure factory function that only returns Handler - Routes will be registered via router package in Phase 5 - Maintains backward compatibility with existing function signature This is Phase 1 of the ebook.go refactoring plan to split the monolithic Handler into focused handlers (MediaHandler, SearchHandler, MatchingHandler). --- internal/handlers/ebook.go | 78 +------------------------------------- 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/internal/handlers/ebook.go b/internal/handlers/ebook.go index 8cc689e..7540374 100644 --- a/internal/handlers/ebook.go +++ b/internal/handlers/ebook.go @@ -68,83 +68,7 @@ func parseDate(dateStr string) time.Time { } func SetupRoutes(g *echo.Group, db *database.Queries, connManager *wsync.ConnectionManager) *Handler { - h := NewHandler(db, connManager) - - // Collections API routes - collectionHandler := NewCollectionHandler(db, connManager) - collections := g.Group("/collections") - collections.GET("", collectionHandler.GetCollections) - collections.POST("", collectionHandler.CreateCollection) - collections.GET("/:id", collectionHandler.GetCollection) - collections.PUT("/:id", collectionHandler.UpdateCollection) - collections.DELETE("/:id", collectionHandler.DeleteCollection) - collections.GET("/:id/books", collectionHandler.GetBookCollections) - collections.POST("/:id/books", collectionHandler.AddBooks) - collections.DELETE("/:id/books/:bookId", collectionHandler.RemoveBook) - collections.POST("/:id/books/bulk-remove", collectionHandler.BulkRemoveBooks) - collections.POST("/bulk-add-books", collectionHandler.HandleBulkAddBooks) - collections.POST("/test-rules", collectionHandler.TestRules) - - // Device shelf mapping routes - deviceCollections := g.Group("/devices/:id/collections") - deviceCollections.GET("", collectionHandler.GetDeviceMappings) - deviceCollections.POST("", collectionHandler.CreateDeviceMapping) - deviceCollections.PUT("/:collectionId", collectionHandler.UpdateDeviceMapping) - deviceCollections.DELETE("/:collectionId", collectionHandler.DeleteDeviceMapping) - - // Book matching and linking routes - g.POST("/sync/books/query", h.QueryBooks) - g.POST("/devices/:deviceId/sync/link-book", h.LinkBook) - g.GET("/devices/:deviceId/sync/unlinked-books", h.GetUnlinkedBooks) - g.GET("/devices/:id/file-aliases", h.GetDeviceFileAliases) - g.POST("/devices/:id/file-aliases", h.CreateDeviceFileAlias) - g.PUT("/devices/:id/file-aliases/:aliasId", h.UpdateDeviceFileAlias) - g.DELETE("/devices/:id/file-aliases/:aliasId", h.DeleteDeviceFileAlias) - g.GET("/books/match", h.GetBookMatches) - - // Media item routes (all authenticated users) - g.GET("/media-items", h.ListMediaItems) - g.GET("/media-items/filtered", h.ListMediaItemsFiltered) - g.GET("/media-items/search", h.SearchMediaItems) - g.GET("/media-items/:id", h.GetMediaItem) - g.POST("/media-items/:id/rating", h.CreateMediaRating) - g.GET("/media-items/:id/rating", h.GetMediaRating) - g.PUT("/media-items/:id/rating", h.UpdateMediaRating) - g.DELETE("/media-items/:id/rating", h.DeleteMediaRating) - - // Legacy progress routes (deprecated - use universal progress instead) - g.GET("/media-items/:id/progress", h.GetMediaReadingProgress) - g.PUT("/media-items/:id/progress", h.UpdateMediaReadingProgress) - g.DELETE("/media-items/:id/progress", h.DeleteMediaReadingProgress) - - // Universal Progress routes (Phase 1) - g.GET("/progress/:id", h.GetUniversalProgress) - g.POST("/progress/:id", h.UpdateUniversalProgress) - g.GET("/progress/:id/history", h.GetProgressHistory) - - // Notes routes - g.GET("/media-items/:id/notes", h.GetMediaNotes) - g.POST("/media-items/:id/notes", h.CreateMediaNote) - g.GET("/media-items/:id/notes/:noteId", h.GetMediaNote) - g.PUT("/media-items/:id/notes/:noteId", h.UpdateMediaNote) - g.DELETE("/media-items/:id/notes/:noteId", h.DeleteMediaNote) - - // Highlights routes - g.GET("/media-items/:id/highlights", h.GetMediaHighlights) - g.POST("/media-items/:id/highlights", h.CreateMediaHighlight) - g.GET("/media-items/:id/highlights/:highlightId", h.GetMediaHighlight) - g.PUT("/media-items/:id/highlights/:highlightId", h.UpdateMediaHighlight) - g.DELETE("/media-items/:id/highlights/:highlightId", h.DeleteMediaHighlight) - - // Admin-only routes - admin := g.Group("", AdminMiddleware) - admin.POST("/media-items", h.CreateMediaItem) - admin.PUT("/media-items/:id", h.UpdateMediaItem) - admin.DELETE("/media-items/:id", h.DeleteMediaItem) - - // Scanner routes are registered in router/scanner.go - - return h + return NewHandler(db, connManager) } // ScanEbooksRequest represents the request for scanning ebooks