Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions app/posts/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 2 additions & 6 deletions app/posts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading