From e278ba38d3f9dd057b70e14f2aeef5ef291ca7fd Mon Sep 17 00:00:00 2001 From: sehooh5 Date: Sun, 25 Jan 2026 17:06:50 +0900 Subject: [PATCH 1/3] add router for read post like users --- app/posts/router.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/posts/router.py b/app/posts/router.py index 2315bf3..b5aa119 100644 --- a/app/posts/router.py +++ b/app/posts/router.py @@ -10,6 +10,7 @@ from app.core.router import create_router from app.storage.schemas import ImageUrl from app.storage.service import ImageMetadata, create_presigned_upload_url +from app.users.schemas import UserRead from .schemas import ( PostCompactRead, @@ -158,3 +159,13 @@ async def unlike_post( post_id=post_id, current_user=current_user, ) + + +@router.get("/{post_id}/likes", status_code=status.HTTP_200_OK) +async def read_post_liked_users( + post_service: PostService, + post_id: int, + current_user: CurrentUser, +) -> list[UserRead]: + return [] + # return await post_service.get_post_likes(post_id=post_id, current_user=current_user) From 9777329d65d6df43ce1b9615ae1f76fa0ccc3cac Mon Sep 17 00:00:00 2001 From: sehooh5 Date: Sun, 25 Jan 2026 17:15:35 +0900 Subject: [PATCH 2/3] add service, repository for post like user list --- app/like/repository.py | 13 +++++++++++++ app/posts/router.py | 7 ++++--- app/posts/service.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/like/repository.py b/app/like/repository.py index 2bc3a04..dab958f 100644 --- a/app/like/repository.py +++ b/app/like/repository.py @@ -3,6 +3,7 @@ from app.database.deps import SessionDep from app.like.tables import comment_like_table, post_like_table +from app.users.models import User from app.utils.dependency import dependency @@ -51,6 +52,18 @@ async def remove_all_by_user(self, *, user_id: int): delete(post_like_table).where(post_like_table.c.user_id == user_id) ) + async def find_users_by_post_id(self, *, post_id: int) -> list[User]: + result = await self.session.scalars( + select(User) + .join(post_like_table, User.id == post_like_table.c.user_id) + .where( + post_like_table.c.post_id == post_id, + User.deleted_at.is_(None), + ) + .order_by(User.id) + ) + return list(result.all()) + @dependency class CommentLikeRepository: diff --git a/app/posts/router.py b/app/posts/router.py index b5aa119..1751a45 100644 --- a/app/posts/router.py +++ b/app/posts/router.py @@ -162,10 +162,11 @@ async def unlike_post( @router.get("/{post_id}/likes", status_code=status.HTTP_200_OK) -async def read_post_liked_users( +async def read_post_like_users( post_service: PostService, post_id: int, current_user: CurrentUser, ) -> list[UserRead]: - return [] - # return await post_service.get_post_likes(post_id=post_id, current_user=current_user) + return await post_service.get_post_like_users( + post_id=post_id, current_user=current_user + ) diff --git a/app/posts/service.py b/app/posts/service.py index 3539db4..45f2621 100644 --- a/app/posts/service.py +++ b/app/posts/service.py @@ -12,6 +12,7 @@ from app.storage.deps import S3ClientDep from app.storage.service import get_image_metadata from app.users.models import User +from app.users.schemas import UserRead from app.utils.dependency import dependency from .models import Post, PostImage @@ -280,3 +281,15 @@ async def unlike_post(self, *, post_id: int, current_user: User): user_id=current_user.id, post_id=post_id, ) + + async def get_post_like_users( + self, *, post_id: int, current_user: User + ) -> list[UserRead]: + post = await self.post_repository.find_by_id(post_id=post_id) + if not post: + raise HTTPException(status_code=404, detail="게시물을 찾을 수 없습니다.") + + users = await self.post_like_repository.find_users_by_post_id(post_id=post_id) + return [ + UserRead.from_user(user, current_user_id=current_user.id) for user in users + ] From f86b6b8f4e1d7415de4c29c3709a67795b4f162a Mon Sep 17 00:00:00 2001 From: sehooh5 Date: Sun, 25 Jan 2026 17:25:12 +0900 Subject: [PATCH 3/3] update path --- app/posts/router.py | 6 +++--- app/posts/service.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/posts/router.py b/app/posts/router.py index 1751a45..5e955bd 100644 --- a/app/posts/router.py +++ b/app/posts/router.py @@ -161,12 +161,12 @@ async def unlike_post( ) -@router.get("/{post_id}/likes", status_code=status.HTTP_200_OK) -async def read_post_like_users( +@router.get("/{post_id}/liked-users", status_code=status.HTTP_200_OK) +async def read_post_liked_users( post_service: PostService, post_id: int, current_user: CurrentUser, ) -> list[UserRead]: - return await post_service.get_post_like_users( + return await post_service.get_post_liked_users( post_id=post_id, current_user=current_user ) diff --git a/app/posts/service.py b/app/posts/service.py index 45f2621..392bc94 100644 --- a/app/posts/service.py +++ b/app/posts/service.py @@ -282,7 +282,7 @@ async def unlike_post(self, *, post_id: int, current_user: User): post_id=post_id, ) - async def get_post_like_users( + async def get_post_liked_users( self, *, post_id: int, current_user: User ) -> list[UserRead]: post = await self.post_repository.find_by_id(post_id=post_id)