Skip to content

Commit 0a52ceb

Browse files
authored
Merge pull request #73 from GTable/feature/#72-예약중복등록방지
feat(Reservation): 예약 중복 등록 방지
2 parents 5b7b907 + f7b311f commit 0a52ceb

7 files changed

Lines changed: 60 additions & 2 deletions

File tree

nowait-app-user-api/src/main/java/com/nowait/applicationuser/exception/GlobalExceptionHandler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import com.nowait.domaincorerdb.order.exception.DuplicateOrderException;
2727
import com.nowait.domaincorerdb.order.exception.OrderItemsEmptyException;
2828
import com.nowait.domaincorerdb.order.exception.OrderParameterEmptyException;
29+
import com.nowait.domaincorerdb.reservation.exception.DuplicateReservationException;
2930
import com.nowait.domaincorerdb.reservation.exception.ReservationNotFoundException;
31+
import com.nowait.domaincorerdb.store.exception.StoreWaitingDisabledException;
3032
import com.nowait.domaincorerdb.token.exception.BusinessException;
3133
import com.nowait.domaincorerdb.user.exception.UserNotFoundException;
3234
import com.nowait.domainuserrdb.bookmark.exception.BookmarkOwnerMismatchException;
@@ -162,6 +164,20 @@ public ErrorResponse reservationNotFoundException(ReservationNotFoundException e
162164
return new ErrorResponse(e.getMessage(), NOTFOUND_RESERVATION.getCode());
163165
}
164166

167+
@ResponseStatus(value = BAD_REQUEST)
168+
@ExceptionHandler(DuplicateReservationException.class)
169+
public ErrorResponse duplicateReservationException(DuplicateReservationException e) {
170+
log.error("duplicateReservationException", e);
171+
return new ErrorResponse(e.getMessage(), DUPLICATE_RESERVATION.getCode());
172+
}
173+
174+
@ResponseStatus(value = BAD_REQUEST)
175+
@ExceptionHandler(StoreWaitingDisabledException.class)
176+
public ErrorResponse storeWaitingDisabledException(StoreWaitingDisabledException e) {
177+
log.error("storeWaitingDisabledException", e);
178+
return new ErrorResponse(e.getMessage(), STORE_WAITING_DISABLED.getCode());
179+
}
180+
165181

166182
private static Map<String, String> getErrors(MethodArgumentNotValidException e) {
167183
return e.getBindingResult()

nowait-app-user-api/src/main/java/com/nowait/applicationuser/oauth/oauth2/CustomOAuth2UserService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
5454
.profileImage(oAuth2Response.getProfileImage())
5555
.socialType(SocialType.KAKAO)
5656
.role(Role.USER) // 일반 유저 설정
57+
.storeId(0L)
5758
.build();
5859

5960
userRepository.save(user);

nowait-app-user-api/src/main/java/com/nowait/applicationuser/reservation/service/ReservationService.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.nowait.applicationuser.reservation.service;
22

33
import java.time.LocalDateTime;
4+
import java.util.List;
45

56
import org.springframework.stereotype.Service;
67
import org.springframework.transaction.annotation.Transactional;
@@ -9,8 +10,11 @@
910
import com.nowait.applicationuser.reservation.dto.ReservationCreateResponseDto;
1011
import com.nowait.common.enums.ReservationStatus;
1112
import com.nowait.domaincorerdb.reservation.entity.Reservation;
13+
import com.nowait.domaincorerdb.reservation.exception.DuplicateReservationException;
1214
import com.nowait.domaincorerdb.reservation.repository.ReservationRepository;
1315
import com.nowait.domaincorerdb.store.entity.Store;
16+
import com.nowait.domaincorerdb.store.exception.StoreNotFoundException;
17+
import com.nowait.domaincorerdb.store.exception.StoreWaitingDisabledException;
1418
import com.nowait.domaincorerdb.store.repository.StoreRepository;
1519
import com.nowait.domaincorerdb.user.entity.User;
1620
import com.nowait.domaincorerdb.user.exception.UserNotFoundException;
@@ -31,10 +35,21 @@ public class ReservationService {
3135
public ReservationCreateResponseDto create(Long storeId, CustomOAuth2User customOAuth2User,
3236
ReservationCreateRequestDto requestDto) {
3337
Store store = storeRepository.findById(storeId)
34-
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 store"));
38+
.orElseThrow(StoreNotFoundException::new);
3539
User user = userRepository.findById(customOAuth2User.getUserId())
3640
.orElseThrow(UserNotFoundException::new);
37-
41+
// store 웨이팅 비활성화 여부
42+
if (Boolean.FALSE.equals(store.getIsActive()))
43+
throw new StoreWaitingDisabledException();
44+
// 중복 예약 존재 여부 확인
45+
boolean hasOngoingReservation = reservationRepository.existsByUserAndStoreAndStatusIn(
46+
user,
47+
store,
48+
List.of(ReservationStatus.WAITING, ReservationStatus.CALLING)
49+
);
50+
if (hasOngoingReservation) {
51+
throw new DuplicateReservationException();
52+
}
3853
Reservation reservation = Reservation.builder()
3954
.store(store)
4055
.user(user)

nowait-common/src/main/java/com/nowait/common/exception/ErrorMessage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum ErrorMessage {
2727
NOTFOUND_RESERVATION("저장된 예약 정보가 없습니다.", "reservation001"),
2828
RESERVATION_VIEW_UNAUTHORIZED("예약 보기 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "reservation002"),
2929
RESERVATION_UPDATE_UNAUTHORIZED("예약 수정 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "reservation003"),
30+
DUPLICATE_RESERVATION("이미 대기 중인 예약이 존재합니다.", "reservation004"),
3031

3132
// bookmark
3233
DUPLICATE_BOOKMARK("이미 북마크한 주점입니다.", "bookmark001"),
@@ -46,6 +47,7 @@ public enum ErrorMessage {
4647
STORE_VIEW_UNAUTHORIZED("주점 보기 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "store003"),
4748
STORE_UPDATE_UNAUTHORIZED("주점 수정 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "store004"),
4849
STORE_DELETE_UNAUTHORIZED("주점 삭제 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "store005"),
50+
STORE_WAITING_DISABLED("해당 주점은 대기 비활성화된 주점입니다.", "store006"),
4951

5052
// image
5153
IMAGE_FILE_EMPTY("이미지 파일을 업로드 해주세요", "image001"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.nowait.domaincorerdb.reservation.exception;
2+
3+
import com.nowait.common.exception.ErrorMessage;
4+
5+
public class DuplicateReservationException extends RuntimeException {
6+
public DuplicateReservationException() {
7+
super(ErrorMessage.DUPLICATE_RESERVATION.getMessage());
8+
}
9+
}
10+

nowait-domain/domain-core-rdb/src/main/java/com/nowait/domaincorerdb/reservation/repository/ReservationRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import org.springframework.data.jpa.repository.JpaRepository;
66
import org.springframework.stereotype.Repository;
77

8+
import com.nowait.common.enums.ReservationStatus;
89
import com.nowait.domaincorerdb.reservation.entity.Reservation;
10+
import com.nowait.domaincorerdb.store.entity.Store;
11+
import com.nowait.domaincorerdb.user.entity.User;
912

1013
@Repository
1114
public interface ReservationRepository extends JpaRepository<Reservation, Long> {
1215
List<Reservation> findAllByStore_StoreIdOrderByRequestedAtAsc(Long storeId);
16+
boolean existsByUserAndStoreAndStatusIn(User user, Store store, List<ReservationStatus> statuses);
17+
1318
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.nowait.domaincorerdb.store.exception;
2+
3+
import com.nowait.common.exception.ErrorMessage;
4+
5+
public class StoreWaitingDisabledException extends RuntimeException {
6+
public StoreWaitingDisabledException() {
7+
super(ErrorMessage.STORE_WAITING_DISABLED.getMessage());
8+
}
9+
}

0 commit comments

Comments
 (0)