Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.nowait.domaincorerdb.order.exception.DuplicateOrderException;
import com.nowait.domaincorerdb.order.exception.OrderItemsEmptyException;
import com.nowait.domaincorerdb.order.exception.OrderParameterEmptyException;
import com.nowait.domaincorerdb.reservation.exception.DuplicateReservationException;
import com.nowait.domaincorerdb.reservation.exception.ReservationNotFoundException;
import com.nowait.domaincorerdb.store.exception.StoreWaitingDisabledException;
import com.nowait.domaincorerdb.token.exception.BusinessException;
import com.nowait.domaincorerdb.user.exception.UserNotFoundException;
import com.nowait.domainuserrdb.bookmark.exception.BookmarkOwnerMismatchException;
Expand Down Expand Up @@ -162,6 +164,20 @@ public ErrorResponse reservationNotFoundException(ReservationNotFoundException e
return new ErrorResponse(e.getMessage(), NOTFOUND_RESERVATION.getCode());
}

@ResponseStatus(value = BAD_REQUEST)
@ExceptionHandler(DuplicateReservationException.class)
public ErrorResponse duplicateReservationException(DuplicateReservationException e) {
log.error("duplicateReservationException", e);
return new ErrorResponse(e.getMessage(), DUPLICATE_RESERVATION.getCode());
}

@ResponseStatus(value = BAD_REQUEST)
@ExceptionHandler(StoreWaitingDisabledException.class)
public ErrorResponse storeWaitingDisabledException(StoreWaitingDisabledException e) {
log.error("storeWaitingDisabledException", e);
return new ErrorResponse(e.getMessage(), STORE_WAITING_DISABLED.getCode());
}


private static Map<String, String> getErrors(MethodArgumentNotValidException e) {
return e.getBindingResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
.profileImage(oAuth2Response.getProfileImage())
.socialType(SocialType.KAKAO)
.role(Role.USER) // 일반 유저 설정
.storeId(0L)
.build();

userRepository.save(user);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nowait.applicationuser.reservation.service;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -9,8 +10,11 @@
import com.nowait.applicationuser.reservation.dto.ReservationCreateResponseDto;
import com.nowait.common.enums.ReservationStatus;
import com.nowait.domaincorerdb.reservation.entity.Reservation;
import com.nowait.domaincorerdb.reservation.exception.DuplicateReservationException;
import com.nowait.domaincorerdb.reservation.repository.ReservationRepository;
import com.nowait.domaincorerdb.store.entity.Store;
import com.nowait.domaincorerdb.store.exception.StoreNotFoundException;
import com.nowait.domaincorerdb.store.exception.StoreWaitingDisabledException;
import com.nowait.domaincorerdb.store.repository.StoreRepository;
import com.nowait.domaincorerdb.user.entity.User;
import com.nowait.domaincorerdb.user.exception.UserNotFoundException;
Expand All @@ -31,10 +35,21 @@ public class ReservationService {
public ReservationCreateResponseDto create(Long storeId, CustomOAuth2User customOAuth2User,
ReservationCreateRequestDto requestDto) {
Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 store"));
.orElseThrow(StoreNotFoundException::new);
User user = userRepository.findById(customOAuth2User.getUserId())
.orElseThrow(UserNotFoundException::new);

// store 웨이팅 비활성화 여부
if (Boolean.FALSE.equals(store.getIsActive()))
throw new StoreWaitingDisabledException();
// 중복 예약 존재 여부 확인
boolean hasOngoingReservation = reservationRepository.existsByUserAndStoreAndStatusIn(
user,
store,
List.of(ReservationStatus.WAITING, ReservationStatus.CALLING)
);
if (hasOngoingReservation) {
throw new DuplicateReservationException();
}
Reservation reservation = Reservation.builder()
.store(store)
.user(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum ErrorMessage {
NOTFOUND_RESERVATION("저장된 예약 정보가 없습니다.", "reservation001"),
RESERVATION_VIEW_UNAUTHORIZED("예약 보기 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "reservation002"),
RESERVATION_UPDATE_UNAUTHORIZED("예약 수정 권한이 없습니다.(슈퍼계정 or 주점 관리자만 가능)", "reservation003"),
DUPLICATE_RESERVATION("이미 대기 중인 예약이 존재합니다.", "reservation004"),

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

// image
IMAGE_FILE_EMPTY("이미지 파일을 업로드 해주세요", "image001"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.nowait.domaincorerdb.reservation.exception;

import com.nowait.common.exception.ErrorMessage;

public class DuplicateReservationException extends RuntimeException {
public DuplicateReservationException() {
super(ErrorMessage.DUPLICATE_RESERVATION.getMessage());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.nowait.common.enums.ReservationStatus;
import com.nowait.domaincorerdb.reservation.entity.Reservation;
import com.nowait.domaincorerdb.store.entity.Store;
import com.nowait.domaincorerdb.user.entity.User;

@Repository
public interface ReservationRepository extends JpaRepository<Reservation, Long> {
List<Reservation> findAllByStore_StoreIdOrderByRequestedAtAsc(Long storeId);
boolean existsByUserAndStoreAndStatusIn(User user, Store store, List<ReservationStatus> statuses);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.domaincorerdb.store.exception;

import com.nowait.common.exception.ErrorMessage;

public class StoreWaitingDisabledException extends RuntimeException {
public StoreWaitingDisabledException() {
super(ErrorMessage.STORE_WAITING_DISABLED.getMessage());
}
}