refactor(handlers): update all handlers for Echo v5 compatibility
Update all handler functions to use *echo.Context (pointer) instead of echo.Context (value) as required by Echo v5. Changes across all handler files: - analytics.go: Update handler signatures - auth.go: Update authentication handler signatures - book_matching.go: Update matching handler signatures - collections.go: Update collection handler signatures - collections_preview_test.go: Update test signatures - commonhandlers.go: Update common handler signatures - conflicts.go: Update conflict handler signatures - context.go: Update context handler signatures - dashboard.go: Update dashboard handler signatures - devices.go: Update device handler signatures - jobs.go: Update job handler signatures - kobo.go: Update Kobo handler signatures - koreader.go: Update Koreader handler signatures - library.go: Update library handler signatures - matching.go: Update matching handler signatures - media.go: Update media handler signatures - opds.go: Update OPDS handler signatures - progress.go: Update progress handler signatures - queue.go: Update queue handler signatures - refresh_token.go: Update token handler signatures - scanner.go: Update scanner handler signatures - sidecar.go: Update sidecar handler signatures - sync.go: Update sync handler signatures - system_settings.go: Update settings handler signatures - websocket.go: Update WebSocket handler signatures All handlers now properly implement Echo v5's pointer-based context pattern. This change is necessary for type safety and compatibility with Echo v5's improved context handling and WebSocket support.
This commit is contained in:
+33
-33
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
// CreateMediaItemRequest represents the request for creating a media item
|
||||
@@ -104,7 +104,7 @@ func NewMediaHandler(db *database.Queries, libraryService *services.LibraryServi
|
||||
return mh
|
||||
}
|
||||
|
||||
func (h *MediaHandler) DownloadBook(c echo.Context) error {
|
||||
func (h *MediaHandler) DownloadBook(c *echo.Context) error {
|
||||
bookUUID, err := uuid.Parse(c.Param("uuid"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid book UUID"})
|
||||
@@ -159,7 +159,7 @@ type AddToShelfRequest struct {
|
||||
ShelfPosition int `json:"shelf_position"`
|
||||
}
|
||||
|
||||
func (h *MediaHandler) AddToShelf(c echo.Context) error {
|
||||
func (h *MediaHandler) AddToShelf(c *echo.Context) error {
|
||||
deviceUUID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid device ID"})
|
||||
@@ -204,7 +204,7 @@ func (h *MediaHandler) AddToShelf(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MediaHandler) GetShelf(c echo.Context) error {
|
||||
func (h *MediaHandler) GetShelf(c *echo.Context) error {
|
||||
deviceUUID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid device ID"})
|
||||
@@ -287,7 +287,7 @@ func (h *MediaHandler) GetShelf(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MediaHandler) RemoveFromShelf(c echo.Context) error {
|
||||
func (h *MediaHandler) RemoveFromShelf(c *echo.Context) error {
|
||||
deviceUUID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid device ID"})
|
||||
@@ -316,7 +316,7 @@ func (h *MediaHandler) RemoveFromShelf(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MediaHandler) ClearShelf(c echo.Context) error {
|
||||
func (h *MediaHandler) ClearShelf(c *echo.Context) error {
|
||||
deviceUUID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid device ID"})
|
||||
@@ -351,7 +351,7 @@ func (h *MediaHandler) ClearShelf(c echo.Context) error {
|
||||
|
||||
// POST /api/media-items/bulk-delete
|
||||
// Bulk delete media items
|
||||
func (h *MediaHandler) HandleBulkDelete(c echo.Context) error {
|
||||
func (h *MediaHandler) HandleBulkDelete(c *echo.Context) error {
|
||||
var req struct {
|
||||
MediaItemIDs []string `json:"media_item_ids" validate:"required"`
|
||||
}
|
||||
@@ -425,7 +425,7 @@ func (h *MediaHandler) HandleBulkDelete(c echo.Context) error {
|
||||
|
||||
// POST /api/media-items/bulk-update
|
||||
// Bulk update media item metadata
|
||||
func (h *MediaHandler) HandleBulkUpdate(c echo.Context) error {
|
||||
func (h *MediaHandler) HandleBulkUpdate(c *echo.Context) error {
|
||||
var req struct {
|
||||
MediaItemUpdates []struct {
|
||||
MediaItemID string `json:"media_item_id" validate:"required"`
|
||||
@@ -553,7 +553,7 @@ func (h *MediaHandler) HandleBulkUpdate(c echo.Context) error {
|
||||
}
|
||||
|
||||
// ListMediaItems handles GET /api/media-items
|
||||
func (mh *MediaHandler) ListMediaItems(c echo.Context) error {
|
||||
func (mh *MediaHandler) ListMediaItems(c *echo.Context) error {
|
||||
libraryID := c.QueryParam("library_id")
|
||||
sort := c.QueryParam("sort")
|
||||
limit, _ := strconv.Atoi(c.QueryParam("limit"))
|
||||
@@ -658,7 +658,7 @@ func (mh *MediaHandler) ListMediaItems(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaItem handles GET /api/media-items/:id
|
||||
func (mh *MediaHandler) GetMediaItem(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaItem(c *echo.Context) error {
|
||||
mediaID := c.Param("id")
|
||||
mediaUUID, err := uuid.Parse(mediaID)
|
||||
if err != nil {
|
||||
@@ -703,7 +703,7 @@ func (mh *MediaHandler) GetMediaItem(c echo.Context) error {
|
||||
}
|
||||
|
||||
// ListMediaItemsFiltered handles GET /api/media-items/filtered
|
||||
func (mh *MediaHandler) ListMediaItemsFiltered(c echo.Context) error {
|
||||
func (mh *MediaHandler) ListMediaItemsFiltered(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
libraryID := c.QueryParam("library_id")
|
||||
sort := c.QueryParam("sort")
|
||||
@@ -766,7 +766,7 @@ func (mh *MediaHandler) ListMediaItemsFiltered(c echo.Context) error {
|
||||
}
|
||||
|
||||
// CreateMediaRating handles POST /api/media-items/:id/rating
|
||||
func (mh *MediaHandler) CreateMediaRating(c echo.Context) error {
|
||||
func (mh *MediaHandler) CreateMediaRating(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -802,7 +802,7 @@ func (mh *MediaHandler) CreateMediaRating(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaRating handles GET /api/media-items/:id/rating
|
||||
func (mh *MediaHandler) GetMediaRating(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaRating(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -830,12 +830,12 @@ func (mh *MediaHandler) GetMediaRating(c echo.Context) error {
|
||||
}
|
||||
|
||||
// UpdateMediaRating handles PUT /api/media-items/:id/rating
|
||||
func (mh *MediaHandler) UpdateMediaRating(c echo.Context) error {
|
||||
func (mh *MediaHandler) UpdateMediaRating(c *echo.Context) error {
|
||||
return mh.CreateMediaRating(c)
|
||||
}
|
||||
|
||||
// DeleteMediaRating handles DELETE /api/media-items/:id/rating
|
||||
func (mh *MediaHandler) DeleteMediaRating(c echo.Context) error {
|
||||
func (mh *MediaHandler) DeleteMediaRating(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -860,7 +860,7 @@ func (mh *MediaHandler) DeleteMediaRating(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaReadingProgress handles GET /api/media-items/:id/progress
|
||||
func (mh *MediaHandler) GetMediaReadingProgress(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaReadingProgress(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -891,7 +891,7 @@ func (mh *MediaHandler) GetMediaReadingProgress(c echo.Context) error {
|
||||
}
|
||||
|
||||
// UpdateMediaReadingProgress handles PUT /api/media-items/:id/progress
|
||||
func (mh *MediaHandler) UpdateMediaReadingProgress(c echo.Context) error {
|
||||
func (mh *MediaHandler) UpdateMediaReadingProgress(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -929,7 +929,7 @@ func (mh *MediaHandler) UpdateMediaReadingProgress(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DeleteMediaReadingProgress handles DELETE /api/media-items/:id/progress
|
||||
func (mh *MediaHandler) DeleteMediaReadingProgress(c echo.Context) error {
|
||||
func (mh *MediaHandler) DeleteMediaReadingProgress(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -954,7 +954,7 @@ func (mh *MediaHandler) DeleteMediaReadingProgress(c echo.Context) error {
|
||||
}
|
||||
|
||||
// CreateMediaItem handles POST /api/media-items (admin only)
|
||||
func (mh *MediaHandler) CreateMediaItem(c echo.Context) error {
|
||||
func (mh *MediaHandler) CreateMediaItem(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
if user.Role != "admin" {
|
||||
@@ -1045,7 +1045,7 @@ func (mh *MediaHandler) CreateMediaItem(c echo.Context) error {
|
||||
}
|
||||
|
||||
// UpdateMediaItem handles PUT /api/media-items/:id (admin only)
|
||||
func (mh *MediaHandler) UpdateMediaItem(c echo.Context) error {
|
||||
func (mh *MediaHandler) UpdateMediaItem(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
if user.Role != "admin" {
|
||||
@@ -1114,7 +1114,7 @@ func (mh *MediaHandler) UpdateMediaItem(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DeleteMediaItem handles DELETE /api/media-items/:id (admin only)
|
||||
func (mh *MediaHandler) DeleteMediaItem(c echo.Context) error {
|
||||
func (mh *MediaHandler) DeleteMediaItem(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
if user.Role != "admin" {
|
||||
@@ -1136,7 +1136,7 @@ func (mh *MediaHandler) DeleteMediaItem(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaNotes handles GET /api/media-items/:id/notes
|
||||
func (mh *MediaHandler) GetMediaNotes(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaNotes(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -1161,7 +1161,7 @@ func (mh *MediaHandler) GetMediaNotes(c echo.Context) error {
|
||||
}
|
||||
|
||||
// CreateMediaNote handles POST /api/media-items/:id/notes
|
||||
func (mh *MediaHandler) CreateMediaNote(c echo.Context) error {
|
||||
func (mh *MediaHandler) CreateMediaNote(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -1196,7 +1196,7 @@ func (mh *MediaHandler) CreateMediaNote(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaNote handles GET /api/media-items/:id/notes/:noteId
|
||||
func (mh *MediaHandler) GetMediaNote(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaNote(c *echo.Context) error {
|
||||
noteID := c.Param("noteId")
|
||||
noteUUID, err := uuid.Parse(noteID)
|
||||
if err != nil {
|
||||
@@ -1215,7 +1215,7 @@ func (mh *MediaHandler) GetMediaNote(c echo.Context) error {
|
||||
}
|
||||
|
||||
// UpdateMediaNote handles PUT /api/media-items/:id/notes/:noteId
|
||||
func (mh *MediaHandler) UpdateMediaNote(c echo.Context) error {
|
||||
func (mh *MediaHandler) UpdateMediaNote(c *echo.Context) error {
|
||||
noteID := c.Param("noteId")
|
||||
noteUUID, err := uuid.Parse(noteID)
|
||||
if err != nil {
|
||||
@@ -1243,7 +1243,7 @@ func (mh *MediaHandler) UpdateMediaNote(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DeleteMediaNote handles DELETE /api/media-items/:id/notes/:noteId
|
||||
func (mh *MediaHandler) DeleteMediaNote(c echo.Context) error {
|
||||
func (mh *MediaHandler) DeleteMediaNote(c *echo.Context) error {
|
||||
noteID := c.Param("noteId")
|
||||
noteUUID, err := uuid.Parse(noteID)
|
||||
if err != nil {
|
||||
@@ -1259,7 +1259,7 @@ func (mh *MediaHandler) DeleteMediaNote(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaHighlights handles GET /api/media-items/:id/highlights
|
||||
func (mh *MediaHandler) GetMediaHighlights(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaHighlights(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -1284,7 +1284,7 @@ func (mh *MediaHandler) GetMediaHighlights(c echo.Context) error {
|
||||
}
|
||||
|
||||
// CreateMediaHighlight handles POST /api/media-items/:id/highlights
|
||||
func (mh *MediaHandler) CreateMediaHighlight(c echo.Context) error {
|
||||
func (mh *MediaHandler) CreateMediaHighlight(c *echo.Context) error {
|
||||
userID := c.Get("user_id").(string)
|
||||
userUUID, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
@@ -1336,7 +1336,7 @@ func (mh *MediaHandler) CreateMediaHighlight(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetMediaHighlight handles GET /api/media-items/:id/highlights/:highlightId
|
||||
func (mh *MediaHandler) GetMediaHighlight(c echo.Context) error {
|
||||
func (mh *MediaHandler) GetMediaHighlight(c *echo.Context) error {
|
||||
highlightID := c.Param("highlightId")
|
||||
highlightUUID, err := uuid.Parse(highlightID)
|
||||
if err != nil {
|
||||
@@ -1355,7 +1355,7 @@ func (mh *MediaHandler) GetMediaHighlight(c echo.Context) error {
|
||||
}
|
||||
|
||||
// UpdateMediaHighlight handles PUT /api/media-items/:id/highlights/:highlightId
|
||||
func (mh *MediaHandler) UpdateMediaHighlight(c echo.Context) error {
|
||||
func (mh *MediaHandler) UpdateMediaHighlight(c *echo.Context) error {
|
||||
highlightID := c.Param("highlightId")
|
||||
highlightUUID, err := uuid.Parse(highlightID)
|
||||
if err != nil {
|
||||
@@ -1400,7 +1400,7 @@ func (mh *MediaHandler) UpdateMediaHighlight(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DeleteMediaHighlight handles DELETE /api/media-items/:id/highlights/:highlightId
|
||||
func (mh *MediaHandler) DeleteMediaHighlight(c echo.Context) error {
|
||||
func (mh *MediaHandler) DeleteMediaHighlight(c *echo.Context) error {
|
||||
highlightID := c.Param("highlightId")
|
||||
highlightUUID, err := uuid.Parse(highlightID)
|
||||
if err != nil {
|
||||
@@ -1416,7 +1416,7 @@ func (mh *MediaHandler) DeleteMediaHighlight(c echo.Context) error {
|
||||
}
|
||||
|
||||
// SearchMediaItems handles GET /api/media-items/search
|
||||
func (mh *MediaHandler) SearchMediaItems(c echo.Context) error {
|
||||
func (mh *MediaHandler) SearchMediaItems(c *echo.Context) error {
|
||||
query := c.QueryParam("q")
|
||||
|
||||
// Safely get user from context
|
||||
@@ -1510,7 +1510,7 @@ func (mh *MediaHandler) getFullFilePath(ctx context.Context, libraryID pgtype.UU
|
||||
|
||||
// ServeFile serves files (covers or books) via /uploads/library-{id}/path
|
||||
// Requires JWT authentication
|
||||
func (mh *MediaHandler) ServeFile(c echo.Context) error {
|
||||
func (mh *MediaHandler) ServeFile(c *echo.Context) error {
|
||||
// URL format: /uploads/library-{libraryID}/{relativePath}
|
||||
// Get library ID directly from route parameter
|
||||
libraryIDStr := c.Param("id")
|
||||
|
||||
Reference in New Issue
Block a user