From a96537e414db6e0bf4a0f2fcf73da9b01db3b996 Mon Sep 17 00:00:00 2001 From: Minkyu Lee Date: Sat, 6 Jul 2024 21:20:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=AF=BC=EA=B0=90=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=EB=8A=94=20list=20api=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- waffledotcom/src/apps/user/schemas.py | 28 +++++++++++++++++++++++++- waffledotcom/src/apps/user/services.py | 10 ++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/waffledotcom/src/apps/user/schemas.py b/waffledotcom/src/apps/user/schemas.py index 977d31c..84a4d67 100644 --- a/waffledotcom/src/apps/user/schemas.py +++ b/waffledotcom/src/apps/user/schemas.py @@ -51,13 +51,39 @@ def from_orm(position: Position) -> PositionDto: ) +class SimpleUserResponse(BaseModel): + id: int + username: str | None + first_name: str + last_name: str + image_url: str | None = None + positions: list[PositionDto] + github_id: str | None + slack_id: str | None + introduction: str | None + + @staticmethod + def from_orm(user: User) -> SimpleUserResponse: + return SimpleUserResponse( + id=user.id, + username=user.username, + first_name=user.first_name, + last_name=user.last_name, + image_url=user.image_url, + positions=[PositionDto.from_orm(pos) for pos in user.positions], + github_id=user.github_id, + slack_id=user.slack_id, + introduction=user.introduction, + ) + + class UserDetailResponse(BaseModel): id: int sso_id: str | None username: str | None first_name: str - image_url: str | None = None last_name: str + image_url: str | None = None positions: list[PositionDto] department: str | None college: str | None diff --git a/waffledotcom/src/apps/user/services.py b/waffledotcom/src/apps/user/services.py index bb629b5..f3ffe19 100644 --- a/waffledotcom/src/apps/user/services.py +++ b/waffledotcom/src/apps/user/services.py @@ -8,9 +8,9 @@ from waffledotcom.src.apps.user.models import User from waffledotcom.src.apps.user.repositories import UserRepository from waffledotcom.src.apps.user.schemas import ( + SimpleUserResponse, UserCreateResponse, UserCreateUpdateRequest, - UserDetailResponse, ) from waffledotcom.src.batch.slack.schema import SlackMember @@ -95,7 +95,7 @@ def create_or_update_user_from_slack(self, slack_member: SlackMember) -> None: def update_user( self, user_id: int, request: UserCreateUpdateRequest - ) -> UserDetailResponse: + ) -> SimpleUserResponse: user = self.user_repository.get_user_by_id(user_id) if user is None: raise UserNotFoundException @@ -104,8 +104,8 @@ def update_user( if user is None: raise UserNotFoundException - return UserDetailResponse.from_orm(user) + return SimpleUserResponse.from_orm(user) - def list_users(self) -> list[UserDetailResponse]: + def list_users(self) -> list[SimpleUserResponse]: users = self.user_repository.get_users() - return [UserDetailResponse.from_orm(user) for user in users] + return [SimpleUserResponse.from_orm(user) for user in users]