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:
+13
-13
@@ -16,7 +16,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"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
@@ -95,7 +95,7 @@ type AdminUpdateUserRequest struct {
|
||||
}
|
||||
|
||||
// Register handles POST /api/auth/register
|
||||
func (h *AuthHandler) Register(c echo.Context) error {
|
||||
func (h *AuthHandler) Register(c *echo.Context) error {
|
||||
email := c.FormValue("email")
|
||||
username := c.FormValue("username")
|
||||
password := c.FormValue("password")
|
||||
@@ -300,7 +300,7 @@ window.location.href = '/dashboard';
|
||||
}
|
||||
|
||||
// Login handles POST /api/auth/login
|
||||
func (h *AuthHandler) Login(c echo.Context) error {
|
||||
func (h *AuthHandler) Login(c *echo.Context) error {
|
||||
login := c.FormValue("login")
|
||||
password := c.FormValue("password")
|
||||
|
||||
@@ -452,7 +452,7 @@ window.location.href = '%s';
|
||||
}
|
||||
|
||||
// GetProfile handles GET /api/auth/profile
|
||||
func (h *AuthHandler) GetProfile(c echo.Context) error {
|
||||
func (h *AuthHandler) GetProfile(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
firstName := ""
|
||||
@@ -475,7 +475,7 @@ func (h *AuthHandler) GetProfile(c echo.Context) error {
|
||||
|
||||
// UpdateProfile handles PUT /api/auth/profile (self-edit) and PUT /api/auth/profile/:id (admin edit)
|
||||
// Combined handler for both self-service and admin profile updates
|
||||
func (h *AuthHandler) UpdateProfile(c echo.Context) error {
|
||||
func (h *AuthHandler) UpdateProfile(c *echo.Context) error {
|
||||
currentUser := MustGetAuthenticatedUser(c)
|
||||
|
||||
// Determine target user: URL param (admin mode) or current user (self-edit)
|
||||
@@ -603,7 +603,7 @@ func (h *AuthHandler) UpdateProfile(c echo.Context) error {
|
||||
}
|
||||
|
||||
// ListUsers handles GET /api/auth/users
|
||||
func (h *AuthHandler) ListUsers(c echo.Context) error {
|
||||
func (h *AuthHandler) ListUsers(c *echo.Context) error {
|
||||
users, err := h.db.ListUsers(c.Request().Context())
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
@@ -641,7 +641,7 @@ type UpdateThemeRequest struct {
|
||||
}
|
||||
|
||||
// UpdateTheme handles PUT /api/auth/theme
|
||||
func (h *AuthHandler) UpdateTheme(c echo.Context) error {
|
||||
func (h *AuthHandler) UpdateTheme(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
var req UpdateThemeRequest
|
||||
@@ -668,7 +668,7 @@ type UpdateUsernameRequest struct {
|
||||
}
|
||||
|
||||
// UpdateUsername handles PUT /api/auth/username
|
||||
func (h *AuthHandler) UpdateUsername(c echo.Context) error {
|
||||
func (h *AuthHandler) UpdateUsername(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
var req UpdateUsernameRequest
|
||||
@@ -702,7 +702,7 @@ type UpdateEmailRequest struct {
|
||||
}
|
||||
|
||||
// UpdateEmail handles PUT /api/auth/email
|
||||
func (h *AuthHandler) UpdateEmail(c echo.Context) error {
|
||||
func (h *AuthHandler) UpdateEmail(c *echo.Context) error {
|
||||
user := MustGetAuthenticatedUser(c)
|
||||
|
||||
var req UpdateEmailRequest
|
||||
@@ -739,7 +739,7 @@ type UpdatePasswordRequest struct {
|
||||
|
||||
// UpdatePassword handles PUT /api/auth/password (self-change) and PUT /api/auth/password/:id (admin reset)
|
||||
// Combined handler for both self-service password change and admin password reset
|
||||
func (h *AuthHandler) UpdatePassword(c echo.Context) error {
|
||||
func (h *AuthHandler) UpdatePassword(c *echo.Context) error {
|
||||
currentUser := MustGetAuthenticatedUser(c)
|
||||
|
||||
// Determine target user: URL param (admin mode) or current user (self-change)
|
||||
@@ -820,7 +820,7 @@ func (h *AuthHandler) UpdatePassword(c echo.Context) error {
|
||||
|
||||
// DeleteUser handles DELETE /api/auth/profile (self-deletion) and DELETE /api/auth/profile/:id (admin deletion)
|
||||
// Combined handler for both self-deletion and admin deletion of users
|
||||
func (h *AuthHandler) DeleteUser(c echo.Context) error {
|
||||
func (h *AuthHandler) DeleteUser(c *echo.Context) error {
|
||||
currentUser := MustGetAuthenticatedUser(c)
|
||||
|
||||
// Get target user ID from URL param (admin mode) or use current user (self-deletion)
|
||||
@@ -912,7 +912,7 @@ type UpdateUserMaxDevicesRequest struct {
|
||||
}
|
||||
|
||||
// UpdateUserMaxDevices handles PUT /api/auth/users/:id/max-devices (admin only)
|
||||
func (h *AuthHandler) UpdateUserMaxDevices(c echo.Context) error {
|
||||
func (h *AuthHandler) UpdateUserMaxDevices(c *echo.Context) error {
|
||||
userID := c.Param("id")
|
||||
if userID == "" {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "user id required"})
|
||||
@@ -949,7 +949,7 @@ func (h *AuthHandler) UpdateUserMaxDevices(c echo.Context) error {
|
||||
|
||||
// AdminMiddleware checks if the user has admin role
|
||||
func AdminMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
userRole, exists := c.Get("user_role").(string)
|
||||
if !exists || userRole != "admin" {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "admin access required"})
|
||||
|
||||
Reference in New Issue
Block a user