diff --git a/app/posts/repository.py b/app/posts/repository.py index f6e5d3c..12668cb 100644 --- a/app/posts/repository.py +++ b/app/posts/repository.py @@ -121,29 +121,22 @@ async def save(self, *, post: Post) -> Post: async def update_post( self, *, - post_id: int, + post: Post, title: str, description: str, category: Category, tags: list[str], - ) -> Post | None: - """기본 필드만 SQL로 업데이트""" - - updated_post = await self.session.scalar( - update(Post) - .where(Post.id == post_id) - .values( - title=title, - description=description, - category=category, - tags=tags, - ) - .returning(Post) - .options(joinedload(Post.author), joinedload(Post.images)) - ) + images: list[PostImage], + ) -> Post: + """Post 객체를 직접 수정""" + post.title = title + post.description = description + post.category = category + post.tags = tags + post.images = images await self.session.flush() - return updated_post + return post async def save_post_images( self, *, post_images: list[PostImage] diff --git a/app/posts/service.py b/app/posts/service.py index 415bb67..ad6e43c 100644 --- a/app/posts/service.py +++ b/app/posts/service.py @@ -200,19 +200,15 @@ async def update_post( ) ) - _ = await self.post_repository.save_post_images(post_images=post_images) - updated_post = await self.post_repository.update_post( - post_id=post_id, + post=saved_post, title=post.title, description=post.description, category=post.category, tags=post.tags, + images=post_images, ) - if not updated_post: - raise HTTPException(status_code=400, detail="게시물 수정 실패") - [like_count, comment_count, is_liked] = await asyncio.gather( self.post_like_repository.count_by_id(post_id=post_id), self.comment_repository.count_by_post_id(post_id=post_id),