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:
@@ -15,7 +15,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"
|
||||
)
|
||||
|
||||
type CollectionHandler struct {
|
||||
@@ -86,7 +86,7 @@ type SectionData struct {
|
||||
Priority int `json:"priority"`
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) CreateCollection(c echo.Context) error {
|
||||
func (h *CollectionHandler) CreateCollection(c *echo.Context) error {
|
||||
user := c.Get("user").(database.Users)
|
||||
userUUID := uuid.UUID(user.ID.Bytes)
|
||||
|
||||
@@ -134,7 +134,7 @@ func (h *CollectionHandler) CreateCollection(c echo.Context) error {
|
||||
return c.JSON(http.StatusCreated, response)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetCollections(c echo.Context) error {
|
||||
func (h *CollectionHandler) GetCollections(c *echo.Context) error {
|
||||
includeAuto := c.QueryParam("include_auto") == "true"
|
||||
sortBy := c.QueryParam("sort_by")
|
||||
|
||||
@@ -185,7 +185,7 @@ func (h *CollectionHandler) GetCollections(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetCollection(c echo.Context) error {
|
||||
func (h *CollectionHandler) GetCollection(c *echo.Context) error {
|
||||
collectionID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"})
|
||||
@@ -231,7 +231,7 @@ func (h *CollectionHandler) GetCollection(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) UpdateCollection(c echo.Context) error {
|
||||
func (h *CollectionHandler) UpdateCollection(c *echo.Context) error {
|
||||
collectionID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"})
|
||||
@@ -279,7 +279,7 @@ func (h *CollectionHandler) UpdateCollection(c echo.Context) error {
|
||||
return c.JSON(http.StatusCreated, response)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) DeleteCollection(c echo.Context) error {
|
||||
func (h *CollectionHandler) DeleteCollection(c *echo.Context) error {
|
||||
collectionID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"})
|
||||
@@ -298,7 +298,7 @@ func (h *CollectionHandler) DeleteCollection(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) AddBooks(c echo.Context) error {
|
||||
func (h *CollectionHandler) AddBooks(c *echo.Context) error {
|
||||
collectionID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"})
|
||||
@@ -345,7 +345,7 @@ func (h *CollectionHandler) AddBooks(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) RemoveBook(c echo.Context) error {
|
||||
func (h *CollectionHandler) RemoveBook(c *echo.Context) error {
|
||||
collectionID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"})
|
||||
@@ -385,7 +385,7 @@ type BulkRemoveBooksRequest struct {
|
||||
BookIDs []string `json:"book_ids" validate:"required"`
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) BulkRemoveBooks(c echo.Context) error {
|
||||
func (h *CollectionHandler) BulkRemoveBooks(c *echo.Context) error {
|
||||
collectionID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"})
|
||||
@@ -436,7 +436,7 @@ func (h *CollectionHandler) BulkRemoveBooks(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetDeviceMappings(c echo.Context) error {
|
||||
func (h *CollectionHandler) GetDeviceMappings(c *echo.Context) error {
|
||||
deviceID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid device id"})
|
||||
@@ -475,7 +475,7 @@ func (h *CollectionHandler) GetDeviceMappings(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) CreateDeviceMapping(c echo.Context) error {
|
||||
func (h *CollectionHandler) CreateDeviceMapping(c *echo.Context) error {
|
||||
deviceID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid device id"})
|
||||
@@ -515,7 +515,7 @@ func (h *CollectionHandler) CreateDeviceMapping(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) UpdateDeviceMapping(c echo.Context) error {
|
||||
func (h *CollectionHandler) UpdateDeviceMapping(c *echo.Context) error {
|
||||
mappingID, err := uuid.Parse(c.Param("mappingId"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid mapping id"})
|
||||
@@ -549,7 +549,7 @@ func (h *CollectionHandler) UpdateDeviceMapping(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) DeleteDeviceMapping(c echo.Context) error {
|
||||
func (h *CollectionHandler) DeleteDeviceMapping(c *echo.Context) error {
|
||||
mappingID, err := uuid.Parse(c.Param("mappingId"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid mapping id"})
|
||||
@@ -563,7 +563,7 @@ func (h *CollectionHandler) DeleteDeviceMapping(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetBookCollections(c echo.Context) error {
|
||||
func (h *CollectionHandler) GetBookCollections(c *echo.Context) error {
|
||||
bookID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid book id"})
|
||||
@@ -607,25 +607,25 @@ func textToString(t pgtype.Text) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetCollectionsData(c echo.Context) ([]database.Collections, error) {
|
||||
func (h *CollectionHandler) GetCollectionsData(c *echo.Context) ([]database.Collections, error) {
|
||||
user := c.Get("user").(database.Users)
|
||||
userUUID := uuid.UUID(user.ID.Bytes)
|
||||
return h.collectionService.GetUserCollections(c.Request().Context(), userUUID)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetCollectionData(c echo.Context, collectionID uuid.UUID) (database.Collections, error) {
|
||||
func (h *CollectionHandler) GetCollectionData(c *echo.Context, collectionID uuid.UUID) (database.Collections, error) {
|
||||
return h.collectionService.GetCollection(c.Request().Context(), collectionID)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetCollectionBooksData(c echo.Context, collectionID uuid.UUID) ([]database.GetCollectionItemsRow, error) {
|
||||
func (h *CollectionHandler) GetCollectionBooksData(c *echo.Context, collectionID uuid.UUID) ([]database.GetCollectionItemsRow, error) {
|
||||
return h.collectionService.GetCollectionBooks(c.Request().Context(), collectionID)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetDeviceMappingsData(c echo.Context, deviceID uuid.UUID) ([]database.GetDeviceShelfMappingsRow, error) {
|
||||
func (h *CollectionHandler) GetDeviceMappingsData(c *echo.Context, deviceID uuid.UUID) ([]database.GetDeviceShelfMappingsRow, error) {
|
||||
return h.collectionService.GetDeviceShelfMappings(c.Request().Context(), deviceID)
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) GetUserCollectionsList(c echo.Context) ([]database.Collections, error) {
|
||||
func (h *CollectionHandler) GetUserCollectionsList(c *echo.Context) ([]database.Collections, error) {
|
||||
user := c.Get("user").(database.Users)
|
||||
userUUID := uuid.UUID(user.ID.Bytes)
|
||||
return h.collectionService.GetUserCollections(c.Request().Context(), userUUID)
|
||||
@@ -643,7 +643,7 @@ type BookMatch struct {
|
||||
MatchReason string `json:"match_reason"`
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) TestRules(c echo.Context) error {
|
||||
func (h *CollectionHandler) TestRules(c *echo.Context) error {
|
||||
var req TestRulesRequest
|
||||
if err := c.Bind(&req); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request"})
|
||||
@@ -771,7 +771,7 @@ func (h *CollectionHandler) compareValues(itemValue, operator, ruleValue string)
|
||||
|
||||
// POST /api/collections/bulk-add-books
|
||||
// Bulk add books to multiple collections
|
||||
func (h *CollectionHandler) HandleBulkAddBooks(c echo.Context) error {
|
||||
func (h *CollectionHandler) HandleBulkAddBooks(c *echo.Context) error {
|
||||
user := c.Get("user").(database.Users)
|
||||
userUUID := uuid.UUID(user.ID.Bytes)
|
||||
|
||||
@@ -867,7 +867,7 @@ func (h *CollectionHandler) HandleBulkAddBooks(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) PreviewCollection(c echo.Context) error {
|
||||
func (h *CollectionHandler) PreviewCollection(c *echo.Context) error {
|
||||
user := c.Get("user")
|
||||
if user == nil {
|
||||
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "unauthorized"})
|
||||
|
||||
Reference in New Issue
Block a user