diff --git a/watchapedia/app/participant/repository.py b/watchapedia/app/participant/repository.py index cf73255..6e146c5 100644 --- a/watchapedia/app/participant/repository.py +++ b/watchapedia/app/participant/repository.py @@ -86,6 +86,14 @@ def like_participant(self, user_id: int, participant: Participant) -> None: return participant + def like_info(self, user_id: int, participant: Participant) -> bool: + get_participant_like_query = select(UserLikesParticipant).filter( + (UserLikesParticipant.user_id == user_id) + & (UserLikesParticipant.participant_id == participant.id) + ) + user_likes_participant = self.session.scalar(get_participant_like_query) + return user_likes_participant is not None + def get_like_participant_list(self, user_id: int) -> list[Participant]: get_like_participant_query = select(Participant).join(UserLikesParticipant, Participant.id == UserLikesParticipant.participant_id).filter( UserLikesParticipant.user_id == user_id diff --git a/watchapedia/app/participant/service.py b/watchapedia/app/participant/service.py index 46657d7..c38f5fc 100644 --- a/watchapedia/app/participant/service.py +++ b/watchapedia/app/participant/service.py @@ -59,6 +59,12 @@ def like_participant(self, user_id: int, participant_id: int) -> ParticipantProf updated_participant = self.participant_repository.like_participant(user_id, participant) return self._process_participant(updated_participant) + def like_info(self, user_id: int, participant_id: int) -> bool: + participant = self.participant_repository.get_participant_by_id(participant_id) + if participant is None: + raise ParticipantNotFoundError() + return self.participant_repository.like_info(user_id, participant) + def get_like_participant_list(self, user_id: int) -> list[ParticipantProfileResponse]: participants = self.participant_repository.get_like_participant_list(user_id) return [self._process_participant(participant) for participant in participants] diff --git a/watchapedia/app/participant/views.py b/watchapedia/app/participant/views.py index 9523e5f..f533648 100644 --- a/watchapedia/app/participant/views.py +++ b/watchapedia/app/participant/views.py @@ -66,4 +66,16 @@ def like_participant( participant_id: int, participant_service: Annotated[ParticipantService, Depends()], ): - return participant_service.like_participant(user.id, participant_id) \ No newline at end of file + return participant_service.like_participant(user.id, participant_id) + +@participant_router.get('/like/{participant_id}', + status_code=200, + summary="인물 추천 여부 확인", + description="[로그인 필요]인물 id를 받아 해당 인물이 추천되어 있는지 여부를 반환합니다.", + ) +def check_like_participant( + user: Annotated[User, Depends(login_with_header)], + participant_id: int, + participant_service: Annotated[ParticipantService, Depends()], +) -> bool: + return participant_service.like_info(user.id, participant_id) \ No newline at end of file