Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: 내가 받은 리뷰 목록에 페이지네이션 적용 #683

Merged
merged 41 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b85e6d2
test: RestDocs로 API 테스트 작성
nayonsoso Sep 24, 2024
b8b3666
refactor: 함수명, 변수명 병경
nayonsoso Sep 24, 2024
8c238a2
feat: 리뷰그룹에 대한 리뷰를 페이징해서 가져오는 함수 생성
nayonsoso Sep 24, 2024
2b3bb9a
feat: 페이지네이션을 사용해서 리뷰 목록 매핑하는 함수 생성
nayonsoso Sep 24, 2024
34077d6
feat: 페이지네이션을 사용해서 리뷰 목록 응답하는 서비스 함수 생성
nayonsoso Sep 24, 2024
79b4bda
refactor: 서비스 함수 바뀐 메서드 시그니처 적용
nayonsoso Sep 24, 2024
5c30f34
feat: 마지막 리뷰 아이디 기본값 설정 추가
nayonsoso Sep 24, 2024
787e707
chore: 코드 정렬
nayonsoso Sep 24, 2024
fc28d73
test: 페이지네이션 적용된 리뷰 목록 조회 테스트 작성
nayonsoso Sep 24, 2024
f0fa9c6
fix: 깨진 테스트 수정
nayonsoso Sep 24, 2024
8443181
refactor: 인자명, 변수명 변경
nayonsoso Sep 25, 2024
ecb444b
refactor: 변수명 변경
nayonsoso Sep 25, 2024
d2064d4
refactor: 오타 수정
nayonsoso Sep 25, 2024
34702c7
test: 수정한 함수를 사용해서 검증하도록 변경
nayonsoso Sep 25, 2024
a530a67
test: 마지막 리뷰 아이디 검증 추가
nayonsoso Sep 25, 2024
1ac7f16
refactor: 레포지토리 함수 이름 수정
nayonsoso Sep 26, 2024
88eea36
refactor: 응답 dto 레코드 이름 수정
nayonsoso Sep 26, 2024
1dceecb
feat: 페이지 크기를 포장하는 객체 생성
nayonsoso Sep 26, 2024
b865dce
feat: 페이지 크기 객체 적용
nayonsoso Sep 26, 2024
89cdb58
Merge remote-tracking branch 'refs/remotes/origin/develop' into be/fe…
nayonsoso Sep 26, 2024
b825f1b
fix: 컴파일 에러 해결
nayonsoso Sep 26, 2024
2b6f268
refactor: 세션-페이지네이션 컨트롤러 통합
nayonsoso Sep 26, 2024
622ea23
refactor: 세션-페이지네이션 API 문서 통합
nayonsoso Sep 26, 2024
840f337
refactor: 세션-페이지네이션 서비스 함수 통합
nayonsoso Sep 26, 2024
c793331
refactor: 사용하지 않는 dto 제거
nayonsoso Sep 26, 2024
d40ded6
refactor: 응답 dto 이름 변경
nayonsoso Sep 26, 2024
9364818
refactor: 컨트롤러 함수 이름 변경
nayonsoso Sep 26, 2024
ea61130
feat: 마지막에 조회된 리뷰 아이디를 포장하는 객체 생성
nayonsoso Sep 26, 2024
cb1c797
refactor: 포장 객체 적용
nayonsoso Sep 26, 2024
d4d546c
refactor: 서비스 함수 인자 순서 변경
nayonsoso Sep 26, 2024
3dcaeaf
refactor: 변수명 변경
nayonsoso Sep 26, 2024
1548304
chore: 주석 추가
nayonsoso Sep 26, 2024
5076911
test: 테스트 데이터를 경계값으로 설정
nayonsoso Sep 26, 2024
b83f55f
test: lastReviewId 를 통일
nayonsoso Sep 26, 2024
708afd2
refactor: 사용되지 않는 attribute 제거
nayonsoso Sep 26, 2024
8bc24d2
chore: 테스트 코드 주석 추가
nayonsoso Sep 26, 2024
cb64bb0
chore: 사용하지 않는 필드 삭제
nayonsoso Sep 26, 2024
7588097
refactor: 쿼리 사용으로 객체 대체
nayonsoso Sep 26, 2024
e86f4df
chore: 사용하지 않는 함수 삭제
nayonsoso Sep 26, 2024
fc5f345
refactor: 기본으로 제공할 리뷰 수 수정
nayonsoso Sep 26, 2024
7954cc4
fix: 깨진 테스트 코드 해결
nayonsoso Sep 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
List<Review> findByReviewGroupIdWithPagination(long reviewGroupId, long lastReviewId, int limit);

Optional<Review> findByIdAndReviewGroupId(long reviewId, long reviewGroupId);

int countByReviewGroupId(long id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제했습니다!

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reviewme.review.repository.ReviewRepository;
import reviewme.review.service.dto.response.list.ReceivedReviewsResponse;
import reviewme.review.service.dto.response.list.ReceivedReviewsResponseWithPagination;
import reviewme.review.service.dto.response.list.ReviewListElementResponse;
Expand All @@ -19,6 +20,7 @@ public class ReviewListLookupService {

private final ReviewGroupRepository reviewGroupRepository;
private final ReviewListMapper reviewListMapper;
private final ReviewRepository reviewRepository;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 것 같슴다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다🫡


@Transactional(readOnly = true)
public ReceivedReviewsResponse getReceivedReviews(String reviewRequestCode, String groupAccessCode) {
Expand Down Expand Up @@ -53,11 +55,24 @@ public ReceivedReviewsResponse getReceivedReviews2(String reviewRequestCode) {
}

@Transactional(readOnly = true)
public ReceivedReviewsResponseWithPagination getReceivedReviewsWithPagination(String reviewRequestCode) {
public ReceivedReviewsResponseWithPagination getReceivedReviewsWithPagination(String reviewRequestCode,
long lastReviewId, int limit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문) 페이지의 게시물 수를 나타내는 인자를 컨트롤러에서는 size로 서비스부터는 limit로 표현하고 있는데 용어를 다르게 한 이유가 있을까요?

Copy link
Contributor Author

@nayonsoso nayonsoso Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 부분 잘 짚어주셨네요🙇🏻‍♀️
둘 다 의미상으로는 '몇개의 리뷰를 한번에 보여줄 것인가' 를 의미하긴 하지만, 사용되는 곳에 따라서 다른 이름을 붙여줬어요.

쿼리 파라미터에서는 페이징의 개념과 잘어울리는 size 라는 이름을 사용했고,
sql 에서는 limit 라는 키워드에 사용되기 때문에 변수명도 limit 로 사용했어요.

일단 제 의도는 이러한데, 커비처럼 헷갈릴 수 있으니 아래처럼 바꿔볼게요!

  • 컨트롤러 ~ 서비스 : 변수명으로 size 사용
  • 레포지토리 ~ 네이티브 쿼리 : 변수명으로 limit 사용

ReviewGroup reviewGroup = reviewGroupRepository.findByReviewRequestCode(reviewRequestCode)
.orElseThrow(() -> new ReviewGroupNotFoundByReviewRequestCodeException(reviewRequestCode));

List<ReviewListElementResponse> reviewGroupResponse = reviewListMapper.mapToReviewList(reviewGroup);
return null;
List<ReviewListElementResponse> elements
= reviewListMapper.mapToReviewListWithPagination(reviewGroup, lastReviewId, limit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elements보다 더 의미가 담긴 변수명은 어떨까요?
reviewListElements도 길지만 괜찮다고 생각해요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elementsvalue와 비슷한 맥락이라고 생각해요. reviewListResponse, responses로 명명을 바꾸면 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깜짝 제안 :
previewPreviewResponse 는 어떠신지요!

int totalSize = reviewRepository.countByReviewGroupId(reviewGroup.getId());
long newLastReviewId = calculateLastReviewId(elements);
return new ReceivedReviewsResponseWithPagination(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PagedReceivedReviewsResponse는 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 반영했습니다!

reviewGroup.getReviewee(), reviewGroup.getProjectName(), totalSize, newLastReviewId, elements
);
}

private long calculateLastReviewId(List<ReviewListElementResponse> elements) {
if(elements.isEmpty()) {
return 0;
}
return elements.get(elements.size() - 1).reviewId();
}
}