diff --git a/src/main/java/kahlua/KahluaProject/apipayload/code/status/ErrorStatus.java b/src/main/java/kahlua/KahluaProject/apipayload/code/status/ErrorStatus.java index 7cc6547..83b649d 100644 --- a/src/main/java/kahlua/KahluaProject/apipayload/code/status/ErrorStatus.java +++ b/src/main/java/kahlua/KahluaProject/apipayload/code/status/ErrorStatus.java @@ -41,7 +41,7 @@ public enum ErrorStatus implements BaseCode { APPLY_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "APPLY INFO NOT FOUND", "존재하지 않는 지원정보 입니다." ), // 웹소켓 에러 - WEBSOCKET_SESSION_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "WEBSOCKET SESSION UNAUTHORIZED", "웹소켓 연결에 실패했습니다."), + WEBSOCKET_SESSION_UNAUTHORIZED(HttpStatus.BAD_REQUEST, "WEBSOCKET ERROR", "웹소켓 연결 과정에서 에러가 발생했습니다."), // 게시판 에러 IMAGE_NOT_UPLOAD(HttpStatus.BAD_REQUEST, "IMAGE_NOT_UPLOAD", "이미지 업로드 개수를 초과하였습니다."), diff --git a/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepository.java b/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepository.java index bbe91de..08346e3 100644 --- a/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepository.java +++ b/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepository.java @@ -4,10 +4,12 @@ import kahlua.KahluaProject.domain.user.User; import java.time.LocalDate; +import java.time.LocalTime; import java.util.List; public interface ReservationCustomRepository { List findByDate(LocalDate date); List findByUser(User user); + Boolean existByDateAndTime(LocalDate date, LocalTime startTime, LocalTime endTime); } diff --git a/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepositoryImpl.java b/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepositoryImpl.java index 98db251..a33581c 100644 --- a/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepositoryImpl.java +++ b/src/main/java/kahlua/KahluaProject/repository/reservation/ReservationCustomRepositoryImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Repository; import java.time.LocalDate; +import java.time.LocalTime; import java.util.List; import static kahlua.KahluaProject.domain.reservation.QReservation.reservation; @@ -36,4 +37,15 @@ public List findByUser(User user) { .orderBy(reservation.reservationDate.asc(), reservation.startTime.asc()) .fetch(); } + + @Override + public Boolean existByDateAndTime(LocalDate date, LocalTime startTime, LocalTime endTime) { + return jpaQueryFactory + .selectOne() + .from(reservation) + .where(reservation.reservationDate.eq(date) + .and(reservation.startTime.lt(endTime) // 시작 시간이 새로운 예약 종료 시간보다 작고 + .and(reservation.endTime.gt(startTime)))) // 종료 시간이 새로운 예약 시작 시간보다 큰 경우 + .fetchFirst() != null; + } } diff --git a/src/main/java/kahlua/KahluaProject/service/ReservationService.java b/src/main/java/kahlua/KahluaProject/service/ReservationService.java index 98e980b..bd8b90a 100644 --- a/src/main/java/kahlua/KahluaProject/service/ReservationService.java +++ b/src/main/java/kahlua/KahluaProject/service/ReservationService.java @@ -11,6 +11,7 @@ import kahlua.KahluaProject.dto.reservation.response.ReservationResponse; import kahlua.KahluaProject.exception.GeneralException; import kahlua.KahluaProject.repository.reservation.ReservationRepository; +import kahlua.KahluaProject.websocket.WebSocketException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -45,6 +46,10 @@ public ReservationResponse proceed(ReservationProceedRequest reservationProceedR @Transactional public ReservationResponse save(ReservationRequest reservationRequest, String date, Map header) { + if (reservationRepository.existByDateAndTime(toLocalDate(date), reservationRequest.startTime(), reservationRequest.endTime())) { + throw new WebSocketException("해당 시간에 예약내역이 존재합니다."); + } + String email = getValueFromHeader(header, "email"); User user = userService.getUserByEmail(email);