-
Notifications
You must be signed in to change notification settings - Fork 1
[#20] Feat: 호텔 조회 API 구현 #21
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
Conversation
Walkthrough숙소 추천 조회를 위한 REST API를 구현하는 변경사항으로, 커서 기반 페이지네이션 기능을 포함하여 컨트롤러, 서비스, 리포지토리, 엔티티, DTO 및 보안 설정을 추가합니다. Changes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/example/triptalk/domain/tripPlan/entity/Accommodation.java (1)
9-14: JPA 엔티티에서@Setter사용을 재고하세요.JPA 엔티티에
@Setter를 사용하면 의도하지 않은 변경이 발생할 수 있습니다. 필요한 경우 특정 필드에만 개별 setter를 제공하거나, 빌더 패턴만 사용하는 것을 권장합니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/main/java/com/example/triptalk/domain/tripPlan/controller/AccommodationController.java(1 hunks)src/main/java/com/example/triptalk/domain/tripPlan/converter/AccommodationConverter.java(1 hunks)src/main/java/com/example/triptalk/domain/tripPlan/dto/AccommodationResponse.java(1 hunks)src/main/java/com/example/triptalk/domain/tripPlan/entity/Accommodation.java(1 hunks)src/main/java/com/example/triptalk/domain/tripPlan/repository/AccommodationRepository.java(1 hunks)src/main/java/com/example/triptalk/domain/tripPlan/service/AccommodationService.java(1 hunks)src/main/java/com/example/triptalk/domain/tripPlan/service/AccommodationServiceImpl.java(1 hunks)src/main/java/com/example/triptalk/global/config/SecurityConfig.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/main/java/com/example/triptalk/domain/tripPlan/service/AccommodationService.java (1)
src/main/java/com/example/triptalk/domain/tripPlan/dto/AccommodationResponse.java (1)
AccommodationResponse(12-66)
src/main/java/com/example/triptalk/domain/tripPlan/controller/AccommodationController.java (1)
src/main/java/com/example/triptalk/domain/tripPlan/dto/AccommodationResponse.java (1)
AccommodationResponse(12-66)
src/main/java/com/example/triptalk/domain/tripPlan/service/AccommodationServiceImpl.java (2)
src/main/java/com/example/triptalk/domain/tripPlan/converter/AccommodationConverter.java (1)
AccommodationConverter(9-47)src/main/java/com/example/triptalk/domain/tripPlan/dto/AccommodationResponse.java (1)
AccommodationResponse(12-66)
src/main/java/com/example/triptalk/domain/tripPlan/converter/AccommodationConverter.java (1)
src/main/java/com/example/triptalk/domain/tripPlan/dto/AccommodationResponse.java (1)
AccommodationResponse(12-66)
🔇 Additional comments (8)
src/main/java/com/example/triptalk/global/config/SecurityConfig.java (1)
44-47: 변경사항이 올바르게 적용되었습니다.새로운 숙소 조회 엔드포인트를 비인증 사용자에게 공개하는 설정이 기존 패턴과 일관되게 구현되었습니다.
src/main/java/com/example/triptalk/domain/tripPlan/service/AccommodationService.java (1)
5-12: 인터페이스 설계가 명확합니다.커서 기반 페이지네이션을 위한 메서드 시그니처가 적절하게 정의되었으며, Javadoc도 명확합니다.
src/main/java/com/example/triptalk/domain/tripPlan/repository/AccommodationRepository.java (1)
18-24: 커서 기반 쿼리가 올바르게 구현되었습니다.ID 내림차순 정렬과
a.id < :cursorId필터링 조합이 정확하며,Slice사용으로 효율적인 페이지네이션을 구현했습니다.src/main/java/com/example/triptalk/domain/tripPlan/controller/AccommodationController.java (1)
20-47: 컨트롤러 구현이 우수합니다.엔드포인트 구현이 깔끔하며, 특히 Swagger 문서화가 상세하고 사용법까지 포함되어 있어 API 사용자에게 도움이 됩니다.
src/main/java/com/example/triptalk/domain/tripPlan/converter/AccommodationConverter.java (1)
14-24: 엔티티-DTO 변환 로직이 정확합니다.모든 필드가 올바르게 매핑되었습니다.
src/main/java/com/example/triptalk/domain/tripPlan/entity/Accommodation.java (1)
17-33: 엔티티 필드 정의가 적절합니다.모든 필드에 적절한 제약조건과 타입이 지정되었으며, 컬럼 길이도 명시되어 있습니다.
src/main/java/com/example/triptalk/domain/tripPlan/dto/AccommodationResponse.java (1)
14-65: DTO 구조가 깔끔하게 설계되었습니다.커서 기반 페이지네이션에 필요한 모든 필드가 포함되었으며, Swagger 어노테이션으로 API 문서화도 잘 되어 있습니다.
src/main/java/com/example/triptalk/domain/tripPlan/service/AccommodationServiceImpl.java (1)
26-34: 서비스 구현이 간결하고 정확합니다.커서 기반 페이지네이션 로직이 올바르게 구현되었으며,
PageRequest.of(0, PAGE_SIZE)사용이 적절합니다. 읽기 전용 트랜잭션 설정도 적절합니다.
| public static AccommodationResponse.AccommodationListResultDTO toAccommodationListResultDTO(Slice<Accommodation> slice) { | ||
| List<AccommodationResponse.AccommodationDTO> accommodationList = slice.getContent().stream() | ||
| .map(AccommodationConverter::toAccommodationDTO) | ||
| .toList(); | ||
|
|
||
| // 다음 커서 ID는 마지막 항목의 ID | ||
| Long nextCursorId = accommodationList.isEmpty() ? | ||
| null : | ||
| accommodationList.getLast().getId(); | ||
|
|
||
| return AccommodationResponse.AccommodationListResultDTO.builder() | ||
| .accommodationList(accommodationList) | ||
| .accommodationListSize(accommodationList.size()) | ||
| .isFirst(slice.isFirst()) | ||
| .hasNext(slice.hasNext()) | ||
| .nextCursorId(nextCursorId) | ||
| .build(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasNext가 false일 때 nextCursorId를 null로 설정하세요.
현재 구현은 다음 페이지가 없어도 마지막 항목의 ID를 nextCursorId로 반환합니다. 클라이언트는 hasNext를 확인해야 하지만, API를 더 방어적으로 만들기 위해 다음 페이지가 없을 때는 nextCursorId를 null로 설정하는 것이 좋습니다.
다음과 같이 수정하세요:
// 다음 커서 ID는 마지막 항목의 ID
- Long nextCursorId = accommodationList.isEmpty() ?
- null :
- accommodationList.getLast().getId();
+ Long nextCursorId = accommodationList.isEmpty() || !slice.hasNext() ?
+ null :
+ accommodationList.getLast().getId();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public static AccommodationResponse.AccommodationListResultDTO toAccommodationListResultDTO(Slice<Accommodation> slice) { | |
| List<AccommodationResponse.AccommodationDTO> accommodationList = slice.getContent().stream() | |
| .map(AccommodationConverter::toAccommodationDTO) | |
| .toList(); | |
| // 다음 커서 ID는 마지막 항목의 ID | |
| Long nextCursorId = accommodationList.isEmpty() ? | |
| null : | |
| accommodationList.getLast().getId(); | |
| return AccommodationResponse.AccommodationListResultDTO.builder() | |
| .accommodationList(accommodationList) | |
| .accommodationListSize(accommodationList.size()) | |
| .isFirst(slice.isFirst()) | |
| .hasNext(slice.hasNext()) | |
| .nextCursorId(nextCursorId) | |
| .build(); | |
| } | |
| public static AccommodationResponse.AccommodationListResultDTO toAccommodationListResultDTO(Slice<Accommodation> slice) { | |
| List<AccommodationResponse.AccommodationDTO> accommodationList = slice.getContent().stream() | |
| .map(AccommodationConverter::toAccommodationDTO) | |
| .toList(); | |
| // 다음 커서 ID는 마지막 항목의 ID | |
| Long nextCursorId = accommodationList.isEmpty() || !slice.hasNext() ? | |
| null : | |
| accommodationList.getLast().getId(); | |
| return AccommodationResponse.AccommodationListResultDTO.builder() | |
| .accommodationList(accommodationList) | |
| .accommodationListSize(accommodationList.size()) | |
| .isFirst(slice.isFirst()) | |
| .hasNext(slice.hasNext()) | |
| .nextCursorId(nextCursorId) | |
| .build(); | |
| } |
🤖 Prompt for AI Agents
In
src/main/java/com/example/triptalk/domain/tripPlan/converter/AccommodationConverter.java
around lines 29 to 46, the method currently sets nextCursorId to the last item's
ID even when slice.hasNext() is false; change the logic so nextCursorId is null
when there is no next page by checking slice.hasNext() and only assigning the
last item's ID if slice.hasNext() is true (otherwise set null), then return the
DTO with that adjusted value.
#️⃣ 연관된 이슈
📝 작업 내용
📌 공유 사항
✅ 체크리스트
스크린샷 (선택)
💬 리뷰 요구사항 (선택)
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.