From 87a59a3716ad527a2aba0ac86c4b398f6167893d Mon Sep 17 00:00:00 2001 From: Prakash Date: Fri, 18 Jul 2025 03:34:08 +0530 Subject: [PATCH] feat: update search_users method to return UsersDTO and total count --- todo/services/user_service.py | 13 +++++++++++-- todo/views/user.py | 10 +--------- 2 files changed, 12 insertions(+), 11 deletions(-) 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,