[태태] Chapter 8. Spring Security - Security 구조, 폼 로그인#113
Open
EH-OI wants to merge 7 commits into
Open
Conversation
[태태] Chapter 4. 프로젝트 세팅하기 - 아키텍처 구조, Swagger
[태태] Chapter 5. 프로젝트 세팅하기 - API 응답 통일, 에러 핸들러
[태태] Chapter 7. API 설계 심화 - 페이징
DOHOON0127
approved these changes
May 26, 2026
DOHOON0127
left a comment
There was a problem hiding this comment.
고생하셨습니다! auth나 handler 부분도 다음 주차에 같이 만들어주세요~
Comment on lines
+45
to
+83
| @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, response); | ||
| } | ||
| } |
There was a problem hiding this comment.
컨트롤러에 있는 DTO변환이나 커서 조립 로직은 Converter로 빼는 것도 고려해보시면 좋을 것 같습니다~
Comment on lines
+14
to
+39
| public class ReviewQueryServiceImpl { | ||
|
|
||
| private final ReviewRepository reviewRepository; | ||
|
|
||
| public Slice<Review> getMyReviews(Long userId, String cursor, String query, Integer size) { | ||
| PageRequest pageRequest = PageRequest.of(0, size); | ||
|
|
||
| if (query.equalsIgnoreCase("star")) { | ||
| if (cursor.equals("-1")) { | ||
| return reviewRepository.findMyReviewsOrderByStarDesc(userId, pageRequest); | ||
| } else { | ||
| String[] cursorSplit = cursor.split(":"); | ||
| Float cursorStar = Float.parseFloat(cursorSplit[0]); | ||
| Long cursorId = Long.parseLong(cursorSplit[1]); | ||
| return reviewRepository.findMyReviewsByStarCursor(userId, cursorStar, cursorId, pageRequest); | ||
| } | ||
| } else { | ||
| if (cursor.equals("-1")) { | ||
| return reviewRepository.findMyReviewsOrderByIdDesc(userId, pageRequest); | ||
| } else { | ||
| Long cursorId = Long.parseLong(cursor); | ||
| return reviewRepository.findMyReviewsByIdCursor(userId, cursorId, pageRequest); | ||
| } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
여기서 HandlerMethodArgumentResolver 활용하는 방법 찾아보시는 것도 추천드립니다!
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)
💡 함께 공유하고 싶은 부분
🤔 질문
✅ 워크북 체크리스트
✅ 컨벤션 체크리스트
📌 주안점