diff --git a/todo/services/user_service.py b/todo/services/user_service.py index 5182b986..f52fc98f 100644 --- a/todo/services/user_service.py +++ b/todo/services/user_service.py @@ -29,12 +29,21 @@ def get_user_by_id(cls, user_id: str) -> UserModel: return user @classmethod - def search_users(cls, query: str, page: int = 1, limit: int = 10) -> Tuple[List[UserModel], int]: + def search_users(cls, query: str, page: int = 1, limit: int = 10) -> Tuple[List[UsersDTO], int]: """ Search users by name or email using fuzzy search """ cls._validate_search_params(query, page, limit) - return UserRepository.search_users(query, page, limit) + + users, totalCount = UserRepository.search_users(query, page, limit) + usersData = [ + UsersDTO( + id=str(user.id), + name=user.name, + ) + for user in users + ] + return usersData, totalCount @classmethod def get_users_by_ids(cls, user_ids: list[str]) -> list[UserDTO]: diff --git a/todo/views/user.py b/todo/views/user.py index 3bcace4a..cf3efef7 100644 --- a/todo/views/user.py +++ b/todo/views/user.py @@ -106,16 +106,8 @@ def get(self, request: Request): status=status.HTTP_204_NO_CONTENT, ) - user_dtos = [ - UsersDTO( - id=str(user.id), - name=user.name, - ) - for user in users - ] - response_data = UserSearchResponseDTO( - users=user_dtos, + users=users, total_count=total_count, page=page, limit=limit,