Refactor User Response Handling in API Endpoints
- Updated user-related API handlers to return user entities directly instead of using the ToResponse method, simplifying response structures. - Modified service methods to return UserResponse types instead of User, enhancing consistency in response formats. - Improved pagination handling in the response package by setting default values for sorting parameters, ensuring more predictable behavior in API responses.
This commit is contained in:
@@ -137,7 +137,7 @@ func (h *Handler) GetProfile(c echo.Context) error {
|
||||
return response.NotFound(c, "User not found")
|
||||
}
|
||||
|
||||
return response.Success(c, user.ToResponse(), "Profile retrieved successfully")
|
||||
return response.Success(c, user, "Profile retrieved successfully")
|
||||
}
|
||||
|
||||
// UpdateProfile updates current user profile
|
||||
@@ -172,7 +172,7 @@ func (h *Handler) UpdateProfile(c echo.Context) error {
|
||||
return response.BadRequest(c, err.Error(), "")
|
||||
}
|
||||
|
||||
return response.Success(c, user.ToResponse(), "Profile updated successfully")
|
||||
return response.Success(c, user, "Profile updated successfully")
|
||||
}
|
||||
|
||||
// ChangePassword changes current user password
|
||||
@@ -276,7 +276,7 @@ func (h *Handler) CreateUser(c echo.Context) error {
|
||||
return response.BadRequest(c, err.Error(), "")
|
||||
}
|
||||
|
||||
return response.Created(c, user.ToResponse(), "User created successfully")
|
||||
return response.Created(c, user, "User created successfully")
|
||||
}
|
||||
|
||||
// ListUsers lists users with search and filters (admin only)
|
||||
@@ -342,7 +342,7 @@ func (h *Handler) GetUserByID(c echo.Context) error {
|
||||
return response.NotFound(c, "User not found")
|
||||
}
|
||||
|
||||
return response.Success(c, user.ToResponse(), "User retrieved successfully")
|
||||
return response.Success(c, user, "User retrieved successfully")
|
||||
}
|
||||
|
||||
// UpdateUser updates a user (admin only)
|
||||
@@ -380,7 +380,7 @@ func (h *Handler) UpdateUser(c echo.Context) error {
|
||||
return response.BadRequest(c, err.Error(), "")
|
||||
}
|
||||
|
||||
return response.Success(c, user.ToResponse(), "User updated successfully")
|
||||
return response.Success(c, user, "User updated successfully")
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user (admin only)
|
||||
|
||||
Reference in New Issue
Block a user