Files
bookhoard/internal/router/library.go
T
john-okeefe 784326e2c4 refactor(router): update routes and middleware for Echo v5
Update all router files to use Echo v5 APIs and type signatures.

Changes in router.go:
- Replace echomiddleware.Logger() with RequestLogger() (line 144)
- Update import from echo/v4 to echo/v5

Changes in frontend.go:
- Update frontend handler signatures to use *echo.Context
- Fix middleware registration for v5 compatibility

Changes in auth.go, library.go, scanner.go, sync.go, helpers.go:
- Update handler function signatures to *echo.Context
- Ensure consistent type usage across all route handlers

All routes now properly implement Echo v5's middleware and handler patterns.
2026-03-06 14:00:17 -05:00

63 lines
2.1 KiB
Go

package router
import (
"bookhoard/internal/handlers"
"github.com/labstack/echo/v5"
)
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 := cfg.ScannerHandler
// 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("/browse", cfg.LibraryHandler.BrowseDirectories)
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.ScanLibrary(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)
})
// System scan settings (admin-only)
adminLibrary.GET("/scan-settings", cfg.SystemSettingsHandler.GetScanSettings)
adminLibrary.PUT("/scan-settings", cfg.SystemSettingsHandler.UpdateScanSettings)
// 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
}