[태태] Chapter 7. API 설계 심화 - 페이징#92
Merged
Merged
Conversation
|
페이징을 열심히 구현하신 것 같습니다! |
DOHOON0127
approved these changes
May 18, 2026
DOHOON0127
left a comment
There was a problem hiding this comment.
무한 스크롤 구현시 Slice활용이나 정석적인 복함합 키 쿼리 작성은 잘 해주신 것 같습니다. 고생하셧습니다~
Comment on lines
+25
to
+30
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new RuntimeException("해당 유저를 찾을 수 없습니다.")); | ||
|
|
||
| // 미션 찾기 | ||
| Mission mission = missionRepository.findById(missionId) | ||
| .orElseThrow(() -> new RuntimeException("해당 미션을 찾을 수 없습니다.")); |
There was a problem hiding this comment.
현재 유저나 미션을 찾지 못했을때 RuntimeException를 던지고 있는데 RuntimeException같은 공통 예외를 그대로 던지면 어떤 에러인지 추적하기 어렵습니다.
앞서 작성했던 프로젝트 공통 예외 클래스 ProjectException으로 변경하여 글로벌 예외 처리기에서 명확한 에러 코드와 메시지를 내려주도록 하는게 좋을 것 같습니다!
| .missionSpec(um.getMission().getMissionSpec()) | ||
| .deadline(um.getMission().getDeadline()) | ||
| .build()) | ||
| .collect(Collectors.toList()); |
There was a problem hiding this comment.
현재 컨트롤러 메서드 내부를 보면 엔티티 -> DTO 매핑 로직이 직접 노출되어 있습니다. 컨트롤러가 너부 비대해 지는 것은 좋아보이지 않기 때문에 컨버터를 활용해서 별도 클래스로 빼는게 좋아보입니다!
Comment on lines
+44
to
+51
| // 공통 페이징 응답 객체 포장 | ||
| PageResponseDto<MissionResponseDto.MyMissionPreviewDto> response = PageResponseDto.<MissionResponseDto.MyMissionPreviewDto>builder() | ||
| .data(data) | ||
| .listSize(userMissionPage.getSize()) | ||
| .totalPage(userMissionPage.getTotalPages()) | ||
| .totalElements(userMissionPage.getTotalElements()) | ||
| .isFirst(userMissionPage.isFirst()) | ||
| .isLast(userMissionPage.isLast()) |
There was a problem hiding this comment.
이 부분도 제 생각에는 매 컨트롤러마다 반복될 코드같은데 그냥 DTO자체에 정적 팩토리 메서드를 만들어 두는게 나을 것 같습니다!
그러면 컨트롤러에서는 PageResponseDto<...> response = PageResponseDto.of(userMissionPage, data); 이런식으로 한 줄로 쓸 수 있을 것 같아요!
Comment on lines
+45
to
82
| @GetMapping("/my") | ||
| public ApiResponse<CursorResponseDto<ReviewResponseDto.MyReviewDto>> getMyReviews( | ||
| @RequestHeader(name = "userId") Long userId, | ||
| @RequestParam(name = "cursor", defaultValue = "-1") String cursor, | ||
| @RequestParam(name = "query", defaultValue = "id") String query, | ||
| @RequestParam(name = "size", defaultValue = "10") Integer size | ||
| ) { | ||
| Slice<Review> reviewSlice = reviewQueryService.getMyReviews(userId, cursor, query, size); | ||
|
|
||
| List<ReviewResponseDto.MyReviewDto> data = reviewSlice.stream() | ||
| .map(r -> ReviewResponseDto.MyReviewDto.builder() | ||
| .reviewId(r.getId()) | ||
| .storeName(r.getStore().getName()) | ||
| .star(r.getStar()) | ||
| .content(r.getContent()) | ||
| .createdAt(r.getCreatedAt()) | ||
| .build()) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| String nextCursor = null; | ||
| if (reviewSlice.hasNext() && !data.isEmpty()) { | ||
| Review lastReview = reviewSlice.getContent().get(reviewSlice.getContent().size() - 1); | ||
| if (query.equalsIgnoreCase("star")) { | ||
| nextCursor = lastReview.getStar() + ":" + lastReview.getId(); | ||
| } else { | ||
| nextCursor = String.valueOf(lastReview.getId()); | ||
| } | ||
| } | ||
|
|
||
| CursorResponseDto<ReviewResponseDto.MyReviewDto> response = CursorResponseDto.<ReviewResponseDto.MyReviewDto>builder() | ||
| .data(data) | ||
| .hasNext(reviewSlice.hasNext()) | ||
| .nextCursor(nextCursor) | ||
| .pageSize(reviewSlice.getSize()) | ||
| .build(); | ||
| return ApiResponse.onSuccess(GeneralSuccessCode.OK, dummyResponse); | ||
|
|
||
| return ApiResponse.onSuccess(GeneralSuccessCode.OK, response); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✏️ 작업 내용
#️⃣ 연관된 이슈
closes #(issue_num)
💡 함께 공유하고 싶은 부분
🤔 질문
✅ 워크북 체크리스트
✅ 컨벤션 체크리스트
📌 주안점