-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(reservation): 예약 상태 변경 #57
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
The head ref may contain hidden characters: "feature/#55-\uC608\uC57D_\uAE30\uBCF8CRUD"
Conversation
- 상태 변경(update) 코드 추가 - 상태별 예약팀 수 카운트 칼럼 추가
Walkthrough예약 관리 기능이 전반적으로 개선되었습니다. 예약 목록 조회 시 상태별 요약 정보와 함께 상세 목록이 반환되도록 변경되었으며, 예약 상태를 업데이트하는 새로운 PATCH 엔드포인트와 관련 DTO, 서비스 로직이 추가되었습니다. 또한, 예약 목록 조회 시 요청 시간 기준 오름차순 정렬이 적용되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Admin as 관리자(관리자)
participant Controller as ReservationController
participant Service as ReservationService
participant Repository as ReservationRepository
participant Entity as Reservation
Admin->>Controller: PATCH /admin/updates/{reservationId} (status 변경 요청)
Controller->>Service: updateReservationStatus(reservationId, requestDto)
Service->>Repository: findById(reservationId)
Repository-->>Service: Reservation 엔티티 반환
Service->>Entity: updateStatus(status)
Service->>Repository: 저장(변경된 Reservation)
Service-->>Controller: CallGetResponseDto 반환
Controller-->>Admin: ApiResponse.success(CallGetResponseDto)
sequenceDiagram
participant User as 사용자(점주)
participant Controller as ReservationController
participant Service as ReservationService
participant Repository as ReservationRepository
User->>Controller: GET /stores/{storeId}/reservations
Controller->>Service: getReservationListByStoreId(storeId)
Service->>Repository: findAllByStore_StoreIdOrderByRequestedAtAsc(storeId)
Repository-->>Service: Reservation 목록 반환
Service-->>Controller: ReservationStatusSummaryDto 반환
Controller-->>User: ReservationStatusSummaryDto 반환
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 2
🧹 Nitpick comments (4)
src/main/java/com/example/gtable/reservation/dto/ReservationStatusUpdateRequestDto.java (1)
10-12: 요청 DTO에 유효성 검증 어노테이션을 추가하는 것을 고려해보세요.DTO 구조가 깔끔하게 설계되었습니다. 다만 API의 안정성을 높이기 위해 필수 필드에 대한 검증을 추가하면 더욱 좋을 것 같습니다.
+import jakarta.validation.constraints.NotNull; + @Getter @Builder public class ReservationStatusUpdateRequestDto { + @NotNull(message = "예약 상태는 필수입니다") private ReservationStatus status; }src/main/java/com/example/gtable/reservation/controller/ReservationController.java (1)
66-79: 새로운 PATCH 엔드포인트 구현이 잘 되었습니다.예약 상태 업데이트를 위한 RESTful한 API 설계가 적절합니다. Swagger 문서화도 잘 되어 있어 API 사용성이 좋을 것 같습니다.
다만 한 가지 개선 제안이 있습니다:
매개변수 형식을 더 읽기 쉽게 개선할 수 있습니다:
- public ResponseEntity<?> updateReservationStatus(@PathVariable Long reservationId,@RequestBody - ReservationStatusUpdateRequestDto requestDto) { + public ResponseEntity<?> updateReservationStatus(@PathVariable Long reservationId, + @RequestBody ReservationStatusUpdateRequestDto requestDto) {src/main/java/com/example/gtable/reservation/service/ReservationService.java (2)
63-63: 상태별 카운팅 로직이 잘 구현되었지만 성능 개선 여지가 있습니다.현재 구현은 기능적으로 올바르지만, 상태별 카운팅과 DTO 변환을 위해 리스트를 두 번 순회하고 있습니다.
단일 루프로 최적화하여 성능을 개선할 수 있습니다:
// 상태별 카운트 집계 int waitingCount = 0; int confirmedCount = 0; int cancelledCount = 0; int callingCount = 0; List<ReservationGetResponseDto> reservationDtoList = new ArrayList<>(); for (Reservation r : reservations) { - if (r.getStatus() == ReservationStatus.WAITING) waitingCount++; - if (r.getStatus() == ReservationStatus.CONFIRMED) confirmedCount++; - if (r.getStatus() == ReservationStatus.CANCELLED) cancelledCount++; - if (r.getStatus() == ReservationStatus.CALLING) callingCount++; + // 상태별 카운트 증가 + switch (r.getStatus()) { + case WAITING -> waitingCount++; + case CONFIRMED -> confirmedCount++; + case CANCELLED -> cancelledCount++; + case CALLING -> callingCount++; + } reservationDtoList.add(ReservationGetResponseDto.fromEntity(r)); }이렇게 하면 각 예약에 대해 4번의 if 검사 대신 1번의 switch 문으로 처리할 수 있어 더 효율적입니다.
Also applies to: 65-86
87-94: 예약 상태 업데이트 메서드가 깔끔하게 구현되었습니다.트랜잭션 처리와 예외 처리가 적절히 되어 있고, 엔티티의
updateStatus메서드를 활용한 것도 좋은 설계입니다.다만 검증 로직 추가를 고려해보시면 좋을 것 같습니다:
상태 전환 규칙 검증을 추가하면 더 안전한 코드가 될 수 있습니다:
@Transactional public CallGetResponseDto updateReservationStatus(Long reservationId, ReservationStatusUpdateRequestDto requestDto) { Reservation reservation = reservationRepository.findById(reservationId) .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 reservation")); + + // 상태 전환 유효성 검증 (예시) + validateStatusTransition(reservation.getStatus(), requestDto.getStatus()); + reservation.updateStatus(requestDto.getStatus()); return CallGetResponseDto.fromEntity(reservation); }예를 들어, 취소된 예약을 다시 대기 상태로 변경하는 것을 방지하는 등의 비즈니스 규칙을 추가할 수 있습니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/main/java/com/example/gtable/reservation/controller/ReservationController.java(3 hunks)src/main/java/com/example/gtable/reservation/dto/CallGetResponseDto.java(1 hunks)src/main/java/com/example/gtable/reservation/dto/ReservationStatusSummaryDto.java(1 hunks)src/main/java/com/example/gtable/reservation/dto/ReservationStatusUpdateRequestDto.java(1 hunks)src/main/java/com/example/gtable/reservation/entity/Reservation.java(1 hunks)src/main/java/com/example/gtable/reservation/repository/ReservationRepository.java(1 hunks)src/main/java/com/example/gtable/reservation/service/ReservationService.java(2 hunks)
🔇 Additional comments (5)
src/main/java/com/example/gtable/reservation/repository/ReservationRepository.java (1)
10-10: 정렬 기능이 추가된 메서드명 변경이 적절합니다.요청 시간 기준 오름차순 정렬을 메서드명에 명시적으로 표현하여 코드의 가독성과 예측가능성이 향상되었습니다. 이는 예약 목록을 일관된 순서로 제공하는 데 도움이 될 것입니다.
src/main/java/com/example/gtable/reservation/dto/ReservationStatusSummaryDto.java (1)
12-18: 상태 요약 DTO의 구조가 잘 설계되었습니다.상태별 개수와 상세 목록을 하나의 응답으로 제공하는 구조가 매우 실용적입니다. 필드명도 직관적이고 명확하여 API 사용자가 쉽게 이해할 수 있을 것입니다.
src/main/java/com/example/gtable/reservation/controller/ReservationController.java (2)
6-12: 임포트 구문 정리가 잘 되었습니다!와일드카드 임포트에서 구체적인 임포트로 변경하신 것이 좋은 개선사항입니다. 코드의 명확성과 IDE 성능 향상에 도움이 됩니다.
Also applies to: 16-16, 19-20, 23-26
56-56: 반환 타입 변경이 적절합니다.
ReservationStatusSummaryDto로 변경하여 상태별 카운트 정보와 함께 예약 목록을 제공하는 것이 사용자 경험 개선에 도움이 될 것 같습니다.src/main/java/com/example/gtable/reservation/service/ReservationService.java (1)
4-4: 필요한 임포트들이 적절히 추가되었습니다.새로운 기능 구현을 위한 임포트들이 깔끔하게 정리되어 있습니다.
Also applies to: 11-11, 15-16
| public void updateStatus(ReservationStatus status) { | ||
| this.status = status; | ||
| } |
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.
🛠️ Refactor suggestion
상태 업데이트 메서드에 입력값 검증을 추가해주세요.
메서드가 깔끔하게 구현되었지만, null 값에 대한 검증이 없어서 안전성을 높이기 위해 개선이 필요합니다.
public void updateStatus(ReservationStatus status) {
+ if (status == null) {
+ throw new IllegalArgumentException("예약 상태는 null일 수 없습니다.");
+ }
this.status = status;
}📝 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 void updateStatus(ReservationStatus status) { | |
| this.status = status; | |
| } | |
| public void updateStatus(ReservationStatus status) { | |
| if (status == null) { | |
| throw new IllegalArgumentException("예약 상태는 null일 수 없습니다."); | |
| } | |
| this.status = status; | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/example/gtable/reservation/entity/Reservation.java around
lines 39 to 41, the updateStatus method lacks validation for null input, which
can lead to unsafe state changes. Add a null check at the start of the method to
verify that the status parameter is not null, and handle the null case
appropriately, such as throwing an IllegalArgumentException or ignoring the
update, to ensure method robustness.
| public static CallGetResponseDto fromEntity(Reservation reservation) { | ||
| return CallGetResponseDto.builder() | ||
| .id(reservation.getId()) | ||
| .storeId(reservation.getStore().getStoreId()) | ||
| .userName(reservation.getUser().getNickname()) | ||
| .requestedAt(reservation.getRequestedAt()) | ||
| .status(reservation.getStatus().name()) | ||
| .partySize(reservation.getPartySize()) | ||
| .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.
🛠️ Refactor suggestion
fromEntity 메서드에 null 안전성 검증을 추가해주세요.
DTO 변환 로직이 깔끔하게 구현되었습니다. 다만 연관 엔티티들이 null일 가능성에 대비한 안전장치를 추가하면 더욱 안정적인 코드가 될 것입니다.
public static CallGetResponseDto fromEntity(Reservation reservation) {
+ if (reservation == null) {
+ throw new IllegalArgumentException("예약 정보는 null일 수 없습니다.");
+ }
+ if (reservation.getStore() == null || reservation.getUser() == null) {
+ throw new IllegalStateException("예약의 매장 또는 사용자 정보가 누락되었습니다.");
+ }
+
return CallGetResponseDto.builder()
.id(reservation.getId())
.storeId(reservation.getStore().getStoreId())
.userName(reservation.getUser().getNickname())
.requestedAt(reservation.getRequestedAt())
.status(reservation.getStatus().name())
.partySize(reservation.getPartySize())
.build();
}📝 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 CallGetResponseDto fromEntity(Reservation reservation) { | |
| return CallGetResponseDto.builder() | |
| .id(reservation.getId()) | |
| .storeId(reservation.getStore().getStoreId()) | |
| .userName(reservation.getUser().getNickname()) | |
| .requestedAt(reservation.getRequestedAt()) | |
| .status(reservation.getStatus().name()) | |
| .partySize(reservation.getPartySize()) | |
| .build(); | |
| } | |
| public static CallGetResponseDto fromEntity(Reservation reservation) { | |
| if (reservation == null) { | |
| throw new IllegalArgumentException("예약 정보는 null일 수 없습니다."); | |
| } | |
| if (reservation.getStore() == null || reservation.getUser() == null) { | |
| throw new IllegalStateException("예약의 매장 또는 사용자 정보가 누락되었습니다."); | |
| } | |
| return CallGetResponseDto.builder() | |
| .id(reservation.getId()) | |
| .storeId(reservation.getStore().getStoreId()) | |
| .userName(reservation.getUser().getNickname()) | |
| .requestedAt(reservation.getRequestedAt()) | |
| .status(reservation.getStatus().name()) | |
| .partySize(reservation.getPartySize()) | |
| .build(); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/example/gtable/reservation/dto/CallGetResponseDto.java
around lines 20 to 29, the fromEntity method lacks null safety checks for
associated entities like store and user. To fix this, add null checks before
accessing properties of reservation.getStore() and reservation.getUser() to
avoid NullPointerExceptions. Use conditional checks or Optional to safely
retrieve values or provide default values when these related entities are null.
작업 요약
Issue Link
문제점 및 어려움
해결 방안
Reference
Summary by CodeRabbit
신규 기능
버그 수정
기타