modern-agile-team / dongurami-server-v2

1 stars 0 forks source link

동아리 게시글 Pagination 형태로 조회 API #206

Closed hobiJeong closed 3 months ago

hobiJeong commented 4 months ago

JIRA

QYOG-143

Description

조회 시 댓글은 1개만, likeCout와 commentCount를 추가로 가져옵니다.

To Reviewer

CustomVirtualColumn과 쿼리빌더에 custom method를 추가해서 기존에 addSelect 시에 새로운 필드가 엔티티에 매핑되지 않는 문제를 해결했습니다. 반복문 깊이가 좀 있는데 개선할 수 있는 방법이 있거나 다른 생각나는 방법 있으시면 피드백 부탁드립니다.. 처음에 join할 때부터 서브쿼리를 이용해서 댓글을 1개씩만 가져오려고 했었는데 그렇게 되면 각 게시글에 대한 commentCount가 제대로 연산되지 않아서 전부 다 가져오고 1개로 가공하는 작업을 했습니다. skip, take 버그 같은 경우에 Join할 때 condition 인자에 정확한 조건을 넘기면 해결되는 것 같습니다.

Reference Link

https://pietrzakadrian.com/blog/virtual-column-solutions-for-typeorm https://seongsu.me/skill/typeorm-virtual-column-2/ https://github.com/typeorm/typeorm/issues/4742

API

Method Path 설명 작업(추가, 수정, 삭제)
GET /api/clubs/:clubId/posts 동아리 게시글 Pagination 조회 추가