Skip to content

Commit

Permalink
Merge pull request #125 from woogieon8on/feature/reservation
Browse files Browse the repository at this point in the history
#124 Feat: 예약 시간 중복 예외처리 로직 추가
  • Loading branch information
woogieon8on authored Jan 9, 2025
2 parents faf6182 + e10522c commit 95d4d72
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "이미지 업로드 개수를 초과하였습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Reservation> findByDate(LocalDate date);
List<Reservation> findByUser(User user);
Boolean existByDateAndTime(LocalDate date, LocalTime startTime, LocalTime endTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,4 +37,15 @@ public List<Reservation> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -45,6 +46,10 @@ public ReservationResponse proceed(ReservationProceedRequest reservationProceedR
@Transactional
public ReservationResponse save(ReservationRequest reservationRequest, String date, Map<String, Object> header) {

if (reservationRepository.existByDateAndTime(toLocalDate(date), reservationRequest.startTime(), reservationRequest.endTime())) {
throw new WebSocketException("해당 시간에 예약내역이 존재합니다.");
}

String email = getValueFromHeader(header, "email");
User user = userService.getUserByEmail(email);

Expand Down

0 comments on commit 95d4d72

Please sign in to comment.