Files
bookhoard/internal/router/library.go
T
john-okeefe eb73e4a9f9 refactor(handlers): Phase 7 - cleanup ebook.go, remove duplicate methods
- Remove 24 duplicate media CRUD methods from ebook.go (884 lines removed)
- Keep 12 scanner/watch/scheduler methods on Handler
- Move request type declarations to media.go:
  * CreateMediaItemRequest
  * UpdateMediaItemRequest
  * CreateMediaNoteRequest
  * UpdateMediaNoteRequest
  * CreateMediaHighlightRequest
  * UpdateMediaHighlightRequest
- Remove unused imports from ebook.go (strconv, pgx)
- Fix library.go to use MediaHandler.ListMediaItems instead of Handler

ebook.go reduced from 1266 lines to 382 lines (70% reduction)
Handler now has focused responsibility: scanner and scheduler operations only

This completes Phase 7 of the ebook.go refactoring plan.

Result: Clean separation of concerns with no duplicate code
2026-02-07 19:56:52 -05:00

58 lines
1.9 KiB
Go

package router
import (
"bookhoard/internal/handlers"
"github.com/labstack/echo/v4"
)
func registerLibraryRoutes(cfg *Config) {
e := cfg.Echo
// JWT middleware for protected routes
jwtMiddleware := createJWTMiddleware(cfg)
// Protected routes group
protected := e.Group("/api", jwtMiddleware)
// Create handler for library-specific convenience routes
h := handlers.NewHandler(cfg.Queries, cfg.ConnManager)
// Public library types endpoint
e.GET("/api/libraries/types", cfg.LibraryHandler.GetLibraryTypes)
// Library management routes
library := protected.Group("/libraries")
// Admin-only library routes
adminLibrary := library.Group("", handlers.AdminMiddleware)
adminLibrary.POST("", cfg.LibraryHandler.CreateLibrary)
adminLibrary.GET("", cfg.LibraryHandler.ListLibraries)
adminLibrary.GET("/:id", cfg.LibraryHandler.GetLibrary)
adminLibrary.PUT("/:id", cfg.LibraryHandler.UpdateLibrary)
adminLibrary.DELETE("/:id", cfg.LibraryHandler.DeleteLibrary)
adminLibrary.POST("/:id/folders", cfg.LibraryHandler.AddLibraryFolder)
adminLibrary.GET("/:id/folders", cfg.LibraryHandler.GetLibraryFolders)
adminLibrary.DELETE("/:id/folders", cfg.LibraryHandler.DeleteLibraryFolder)
adminLibrary.GET("/:id/stats", cfg.LibraryHandler.GetLibraryStats)
adminLibrary.POST("/:id/scan", func(c echo.Context) error {
libraryID := c.Param("id")
scanReq := map[string]interface{}{
"library_id": libraryID,
}
c.Set("scan_request", scanReq)
return h.ScanEbooks(c)
})
adminLibrary.GET("/:id/media-items", func(c echo.Context) error {
libraryID := c.Param("id")
c.QueryParams().Set("library_id", libraryID)
return cfg.MediaHandler.ListMediaItems(c)
})
// User library visibility control
userLibrary := library.Group("/visibility")
userLibrary.GET("", cfg.LibraryHandler.GetUserVisibleLibraries)
userLibrary.POST("", cfg.LibraryHandler.SetLibraryVisibility)
// Note: Remove endpoint may not exist - check handlers
}