From a8ce49391a8fdcfd5fc089ba5b253e9585988c32 Mon Sep 17 00:00:00 2001 From: Jihun Kim Date: Mon, 5 Jan 2026 17:53:13 +0900 Subject: [PATCH] =?UTF-8?q?bug:=20=EC=9B=A8=EC=9D=B4=ED=8C=85=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=20=EC=8B=9C=20DB=20=EB=A8=BC=EC=A0=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EA=B3=A0=20Redis=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 44 +++++++++++-------- .../repository/ReservationRepository.java | 2 + 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/nowait-app-user-api/src/main/java/com/nowait/applicationuser/reservation/service/ReservationService.java b/nowait-app-user-api/src/main/java/com/nowait/applicationuser/reservation/service/ReservationService.java index ca69a598..2416e0d5 100644 --- a/nowait-app-user-api/src/main/java/com/nowait/applicationuser/reservation/service/ReservationService.java +++ b/nowait-app-user-api/src/main/java/com/nowait/applicationuser/reservation/service/ReservationService.java @@ -1,5 +1,7 @@ package com.nowait.applicationuser.reservation.service; +import static com.nowait.common.exception.ErrorMessage.*; + import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; @@ -215,38 +217,42 @@ public WaitingResponseDto myWaitingInfo(Long storeId, CustomOAuth2User customOAu public boolean cancelWaiting(Long storeId, CustomOAuth2User customOAuth2User) { String userId = customOAuth2User.getUserId().toString(); - if (storeId == null || userId.trim().isEmpty()) { - throw new IllegalArgumentException("Invalid storeId or userId"); + if (storeId == null) { + throw new StoreNotFoundException(); + } + + if (userId.trim().isEmpty()) { + throw new UserNotFoundException(); } String reservationNumber = waitingUserRedisRepository.getReservationId(storeId, userId); if (reservationNumber == null) { - throw new IllegalArgumentException("Waiting not found"); + throw new ReservationNotFoundException(); } Integer partySize = waitingUserRedisRepository.getPartySize(storeId, userId); Long ts = waitingUserRedisRepository.getWaitingTimestamp(storeId, userId); + // 대기열에서 제거 및 결과 반환 - boolean removed = waitingUserRedisRepository.removeWaiting(storeId, userId); - if (!removed) { - throw new IllegalArgumentException("Waiting not found"); - } + if (reservationRepository.existsReservationByReservationNumber(reservationNumber)) { + Reservation reservation = Reservation.builder() + .reservationNumber(reservationNumber) + .partySize(partySize) + .status(ReservationStatus.CANCELLED) + .store(storeRepository.getReferenceById(storeId)) + .user(userRepository.getReferenceById(Long.parseLong(userId))) + .updatedAt(LocalDateTime.now()) + .requestedAt(ts != null ? LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneId.of("Asia/Seoul")) + : LocalDateTime.now()) + .build(); - Reservation reservation = Reservation.builder() - .reservationNumber(reservationNumber) - .partySize(partySize) - .status(ReservationStatus.CANCELLED) - .store(storeRepository.getReferenceById(storeId)) - .user(userRepository.getReferenceById(Long.parseLong(userId))) - .updatedAt(LocalDateTime.now()) - .requestedAt(ts != null ? LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneId.of("Asia/Seoul")) - : LocalDateTime.now()) - .build(); + reservationRepository.save(reservation); + } - reservationRepository.save(reservation); + waitingUserRedisRepository.removeWaiting(storeId, userId); waitingPermitLuaRepository.removeActiveMember(userId, String.valueOf(storeId), reservationNumber); + return true; - // return removed; } //TODO 성능 개선 필요 diff --git a/nowait-domain/domain-core-rdb/src/main/java/com/nowait/domaincorerdb/reservation/repository/ReservationRepository.java b/nowait-domain/domain-core-rdb/src/main/java/com/nowait/domaincorerdb/reservation/repository/ReservationRepository.java index 17e8c36b..5512a5f1 100644 --- a/nowait-domain/domain-core-rdb/src/main/java/com/nowait/domaincorerdb/reservation/repository/ReservationRepository.java +++ b/nowait-domain/domain-core-rdb/src/main/java/com/nowait/domaincorerdb/reservation/repository/ReservationRepository.java @@ -18,6 +18,8 @@ public interface ReservationRepository extends JpaRepository boolean existsByUserAndStoreAndStatusIn(User user, Store store, List statuses); + boolean existsReservationByReservationNumber(String reservationNumber); + Optional findFirstByStore_StoreIdAndUserIdAndStatusInAndRequestedAtBetweenOrderByRequestedAtDesc( Long storeId, Long userId, List statuses, LocalDateTime start, LocalDateTime end);