-
Notifications
You must be signed in to change notification settings - Fork 0
feat(Reservation):예약 리스트 조회 로직 개선 #165
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/#158_Store\uC608\uC57D\uB9CE\uC740\uC21C\uBC18\uD658\uD0C0\uC785\uAC1C\uC120"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
| import java.util.UUID; | ||||
| import java.util.concurrent.ThreadLocalRandom; | ||||
|
|
||||
| import org.springframework.data.redis.core.ZSetOperations; | ||||
| import org.springframework.stereotype.Service; | ||||
|
|
@@ -90,6 +92,7 @@ public CallGetResponseDto updateReservationStatus(Long reservationId, Reservatio | |||
| @Transactional(readOnly = true) | ||||
| public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) { | ||||
| List<ZSetOperations.TypedTuple<String>> waitingList = waitingRedisRepository.getAllWaitingWithScore(storeId); | ||||
| System.out.println(waitingList); | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 디버그 출력문을 제거해주세요. 프로덕션 코드에서 System.out.println은 제거되어야 합니다. 로깅이 필요하다면 적절한 로거를 사용하세요. -System.out.println(waitingList);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
|
|
||||
| return waitingList.stream() | ||||
| .map(tuple -> { | ||||
|
|
@@ -100,18 +103,24 @@ public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) { | |||
| String status = waitingRedisRepository.getWaitingStatus(storeId, userId); | ||||
|
|
||||
| // 2. DB에서 userName, createdAt, reservationId 조회 | ||||
| String userName = null; | ||||
| LocalDateTime createdAt = null; | ||||
| Long reservationId = null; | ||||
|
|
||||
| Optional<Reservation> reservationOpt = reservationRepository.findByStore_StoreIdAndUserId(storeId, Long.valueOf(userId)); | ||||
| //TODO 개선필요 -> createAt 정확성 및 reservationhId 생성 방법(예약생성부터 DB에 박아야하나....) | ||||
| String userName = userRepository.getReferenceById(Long.valueOf(userId)).getNickname(); | ||||
| LocalDateTime createdAt = LocalDateTime.now(); | ||||
| String reservationId = String.valueOf( | ||||
| ThreadLocalRandom.current().nextInt(1, 100)); | ||||
|
|
||||
|
Comment on lines
+107
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예약 ID 생성 로직에 일관성 문제가 있습니다. 현재 로직에서 예약이 없을 때 랜덤 ID를 생성하고, 예약이 있을 때는 데이터베이스 ID를 사용하는 것은 일관성이 없습니다. 또한 TODO 주석에서도 언급된 것처럼, 예약 생성 시점부터 DB에 저장하거나 일관된 ID 생성 전략을 수립해야 합니다. -//TODO 개선필요 -> createAt 정확성 및 reservationhId 생성 방법(예약생성부터 DB에 박아야하나....)
-String userName = userRepository.getReferenceById(Long.valueOf(userId)).getNickname();
-LocalDateTime createdAt = LocalDateTime.now();
-String reservationId = String.valueOf(
- ThreadLocalRandom.current().nextInt(1, 100));
+// 예약이 없는 경우의 기본값 설정을 명확히 하고 일관성 있게 처리
+String userName = null;
+LocalDateTime createdAt = null;
+String reservationId = null;
🤖 Prompt for AI Agents |
||||
| Optional<Reservation> reservationOpt = reservationRepository.findByStore_StoreIdAndUserIdAndRequestedAtBetween( | ||||
| storeId, Long.valueOf(userId), LocalDate.now().atStartOfDay(), LocalDate.now().atTime(LocalTime.MAX)); | ||||
| if (reservationOpt.isPresent()) { | ||||
| Reservation reservation = reservationOpt.get(); | ||||
| createdAt = reservation.getRequestedAt(); | ||||
| reservationId = reservation.getId(); | ||||
| reservationId = reservation.getId().toString(); | ||||
| userName = reservation.getUser().getNickname(); | ||||
| } else { | ||||
| } | ||||
|
|
||||
|
|
||||
|
|
||||
| return new WaitingUserResponse( | ||||
| reservationId != null ? reservationId.toString() : null, | ||||
| userId, | ||||
|
|
@@ -129,7 +138,11 @@ public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) { | |||
| // 완료 or 취소 처리된 대기 리스트 조회 | ||||
| @Transactional(readOnly = true) | ||||
| public List<WaitingUserResponse> getCompletedWaitingUserDetails(Long storeId) { | ||||
| List<Reservation> reservations = reservationRepository.findAllByStore_StoreId(storeId); | ||||
| List<Reservation> reservations = reservationRepository.findAllByStore_StoreIdAndStatusInAndRequestedAtBetween( | ||||
| storeId, | ||||
| List.of(ReservationStatus.CONFIRMED, ReservationStatus.CANCELLED), | ||||
| LocalDate.now().atStartOfDay(), | ||||
| LocalDate.now().atTime(LocalTime.MAX)); | ||||
|
|
||||
| return reservations.stream() | ||||
| .map(r -> WaitingUserResponse.fromEntity(r)) | ||||
|
|
||||
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
반환 타입을 구체적으로 유지하는 것을 권장합니다.
ResponseEntity<?>로 변경하면 타입 안전성이 감소하고 API 계약이 불분명해집니다. 메서드가 실제로는List<WaitingUserResponse>를 반환하므로, 원래의 구체적인 타입ResponseEntity<List<WaitingUserResponse>>을 유지하는 것이 좋습니다.📝 Committable suggestion
🤖 Prompt for AI Agents