diff --git a/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingCustom.java b/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingCustom.java index 19d5d4ba..a1968e57 100644 --- a/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingCustom.java +++ b/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingCustom.java @@ -15,7 +15,7 @@ public interface CarBookingCustom { boolean existsDateTime(Car car, LocalDateTime startDateTime, LocalDateTime endDateTime); - List getCarBookedDate(Car car, LocalDate standardDate, LocalDate date); + List getCarBookedDate(Car car, LocalDate standardDate); ProductBookingRes findCarBookingByDate(Car car, LocalDateTime dateTime); diff --git a/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingRepositoryImpl.java b/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingRepositoryImpl.java index 0eb84666..e018a024 100644 --- a/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingRepositoryImpl.java +++ b/src/main/java/com/example/pladialmserver/booking/repository/carBooking/CarBookingRepositoryImpl.java @@ -19,14 +19,11 @@ import java.time.LocalTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; import static com.example.pladialmserver.booking.entity.QCarBooking.carBooking; -import static com.example.pladialmserver.booking.entity.QResourceBooking.resourceBooking; @RequiredArgsConstructor public class CarBookingRepositoryImpl implements CarBookingCustom { @@ -67,42 +64,26 @@ public ProductBookingRes findCarBookingByDate(Car car, LocalDateTime standardDat } @Override - public List getCarBookedDate(Car car, LocalDate standardDate, LocalDate date) { + public List getCarBookedDate(Car car, LocalDate standardDate) { // 해당 월의 첫 날 (00:00) LocalDateTime startDateTime = standardDate.withDayOfMonth(1).atStartOfDay(); // 다음 월의 첫 날 (00:00) LocalDateTime endDateTime = standardDate.plusMonths(1).atStartOfDay(); - // 이후 가장 가까운 예약 날짜&시간 - if (date != null) { - // 조회 일의 첫 날 (00:00) - LocalDateTime dateTime = date.atStartOfDay(); - // 가장 가까운 예약 현황 조회 - CarBooking booking = jpaQueryFactory.selectFrom(carBooking) - .where(carBooking.car.eq(car), - carBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING), - carBooking.startDate.after(dateTime)) - .orderBy(carBooking.startDate.asc()) - .fetchFirst(); - - return Optional.ofNullable(booking) - .map(b -> Collections.singletonList(DateTimeUtil.dateTimeToString(b.getStartDate()))) - .orElse(null); - } else { - // 해당 월의 예약 현황 조회 - List bookings = jpaQueryFactory.selectFrom(carBooking) - .where(carBooking.car.eq(car) - .and(carBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING)) - .and((carBooking.startDate.between(startDateTime, endDateTime)) - .or(carBooking.endDate.between(startDateTime, endDateTime))) - ).orderBy(carBooking.startDate.asc()) - .fetch(); - - // 예약이 모두 된 날짜(첫 날 0시 ~ 다음 날 0시) 반환 - List bookedDate = new ArrayList<>(); - int index = 0; - boolean isContinuity = false; - LocalDateTime standard = null; + // 해당 월의 예약 현황 조회 + List bookings = jpaQueryFactory.selectFrom(carBooking) + .where(carBooking.car.eq(car) + .and(carBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING)) + .and((carBooking.startDate.between(startDateTime, endDateTime)) + .or(carBooking.endDate.between(startDateTime, endDateTime))) + ).orderBy(carBooking.startDate.asc()) + .fetch(); + + // 예약이 모두 된 날짜(첫 날 0시 ~ 다음 날 0시) 반환 + List bookedDate = new ArrayList<>(); + int index = 0; + boolean isContinuity = false; + LocalDateTime standard = null; for (CarBooking b : bookings) { index++; @@ -140,7 +121,6 @@ public List getCarBookedDate(Car car, LocalDate standardDate, LocalDate standard = b.getEndDate(); } return bookedDate; - } } private boolean isMidnight(LocalDateTime localDateTime) { diff --git a/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingCustom.java b/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingCustom.java index 818e1658..87038aee 100644 --- a/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingCustom.java +++ b/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingCustom.java @@ -14,7 +14,7 @@ public interface ResourceBookingCustom { Page getBookingsByUser(User user, Pageable pageable); boolean existsDateTime(Resource resource, LocalDateTime startDateTime, LocalDateTime endDateTime); - List getResourceBookedDate(Resource resource, LocalDate standardDate, LocalDate date); + List getResourceBookedDate(Resource resource, LocalDate standardDate); void updateBookingStatusForResigning(User user); ProductBookingRes findResourceBookingByDate(Resource resource, LocalDateTime dateTime); diff --git a/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingRepositoryImpl.java b/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingRepositoryImpl.java index c34a776d..a8d31958 100644 --- a/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingRepositoryImpl.java +++ b/src/main/java/com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingRepositoryImpl.java @@ -59,33 +59,17 @@ public Page getBookingsByUser(User user, Pageable pageable) { // 장비 월별 예약 현황 조회 @Override - public List getResourceBookedDate(Resource resource, LocalDate standardDate, LocalDate date) { + public List getResourceBookedDate(Resource resource, LocalDate standardDate) { // 해당 월의 첫 날 (00:00) LocalDateTime startDateTime = standardDate.withDayOfMonth(1).atStartOfDay(); // 다음 월의 첫 날 (00:00) LocalDateTime endDateTime = standardDate.plusMonths(1).atStartOfDay(); - // 이후 가장 가까운 예약 날짜&시간 - if (date != null) { - // 조회 일의 첫 날 (00:00) - LocalDateTime dateTime = date.atStartOfDay(); - // 가장 가까운 예약 현황 조회 - ResourceBooking booking = jpaQueryFactory.selectFrom(resourceBooking) - .where(resourceBooking.resource.eq(resource), - resourceBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING), - resourceBooking.startDate.after(dateTime)) - .orderBy(resourceBooking.startDate.asc()) - .fetchFirst(); - - return Optional.ofNullable(booking) - .map(b -> Collections.singletonList(DateTimeUtil.dateTimeToString(b.getStartDate()))) - .orElse(null); - } else { - // 해당 월의 예약 현황 조회 - List bookings = jpaQueryFactory.selectFrom(resourceBooking) - .where(resourceBooking.resource.eq(resource) - .and(resourceBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING)) - .and((resourceBooking.startDate.between(startDateTime, endDateTime)) + // 해당 월의 예약 현황 조회 + List bookings = jpaQueryFactory.selectFrom(resourceBooking) + .where(resourceBooking.resource.eq(resource) + .and(resourceBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING)) + .and((resourceBooking.startDate.between(startDateTime, endDateTime)) .or(resourceBooking.endDate.between(startDateTime, endDateTime))) ).orderBy(resourceBooking.startDate.asc()) .fetch(); @@ -132,7 +116,6 @@ public List getResourceBookedDate(Resource resource, LocalDate standardD standard = b.getEndDate(); } return bookedDate; - } } private boolean isMidnight(LocalDateTime localDateTime) { diff --git a/src/main/java/com/example/pladialmserver/product/car/controller/CarController.java b/src/main/java/com/example/pladialmserver/product/car/controller/CarController.java index ed982d10..88713116 100644 --- a/src/main/java/com/example/pladialmserver/product/car/controller/CarController.java +++ b/src/main/java/com/example/pladialmserver/product/car/controller/CarController.java @@ -150,6 +150,6 @@ public ResponseCustom> getCarBookedDate( @Parameter(description = "(Long) 차량 Id", example = "1") @PathVariable(name = "carId") Long carId, @Parameter(description = "차량 예약 현황 조회 년도월 (YYYY-MM)", example = "2023-10") @RequestParam String month, @Parameter(description = "차량 예약 현황 조회 날짜 (YYYY-MM-DD)", example = "2023-10-23") @RequestParam(required = false) @DateTimeFormat(pattern = DATE_PATTERN) LocalDate date) { - return ResponseCustom.OK(carService.getProductBookedDate(carId, month, date)); + return ResponseCustom.OK(carService.getProductBookedDate(carId, month)); } } diff --git a/src/main/java/com/example/pladialmserver/product/car/service/CarService.java b/src/main/java/com/example/pladialmserver/product/car/service/CarService.java index ee1b8789..ab0375c0 100644 --- a/src/main/java/com/example/pladialmserver/product/car/service/CarService.java +++ b/src/main/java/com/example/pladialmserver/product/car/service/CarService.java @@ -96,12 +96,12 @@ public ProductBookingRes getProductBookingByDate(Long resourceId, LocalDateTime } @Override - public List getProductBookedDate(Long resourceId, String month, LocalDate date) { + public List getProductBookedDate(Long resourceId, String month) { Car car = carRepository.findById(resourceId) .orElseThrow(() -> new BaseException(BaseResponseCode.CAR_NOT_FOUND)); // 예약 현황 조회할 월 LocalDate standardDate = DateTimeUtil.stringToFirstLocalDate(month); - return carBookingRepository.getCarBookedDate(car, standardDate, date); + return carBookingRepository.getCarBookedDate(car, standardDate); } @Override diff --git a/src/main/java/com/example/pladialmserver/product/resource/controller/ResourceController.java b/src/main/java/com/example/pladialmserver/product/resource/controller/ResourceController.java index 88cdbaa2..19832b6b 100644 --- a/src/main/java/com/example/pladialmserver/product/resource/controller/ResourceController.java +++ b/src/main/java/com/example/pladialmserver/product/resource/controller/ResourceController.java @@ -92,7 +92,7 @@ public ResponseCustom getResourceDetail( /** * 장비 월별 예약 현황 조회 */ - @Operation(summary = "장비 월별 예약 현황 조회 (박소정)", description = "월별로 장비 예약이 불가능한 날짜를 조회를 진행한다. /n 일 기준 예약이 아예 불가한 날짜 반환") + @Operation(summary = "장비 월별 예약 현황 조회 (박소정)", description = "해당 월의 장비 예약이 불가능한 날짜를 조회한다. (YYYY-MM-DD)") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."), @ApiResponse(responseCode = "400", description = "(R0003)존재하지 않는 장비입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))) @@ -101,9 +101,8 @@ public ResponseCustom getResourceDetail( public ResponseCustom> getResourceBookedDate( @Account User user, @Parameter(description = "(Long) 장비 Id", example = "1") @PathVariable(name = "resourceId") Long resourceId, - @Parameter(description = "장비 예약 현황 조회 년도월 (YYYY-MM)", example = "2023-10") @RequestParam String month, - @Parameter(description = "장비 예약 현황 조회 날짜 (YYYY-MM-DD)", example = "2023-10-23") @RequestParam(required = false) @DateTimeFormat(pattern = DATE_PATTERN) LocalDate date) { - return ResponseCustom.OK(resourceService.getProductBookedDate(resourceId, month, date)); + @Parameter(description = "장비 예약 현황 조회 년도월 (YYYY-MM)", example = "2023-10") @RequestParam String month) { + return ResponseCustom.OK(resourceService.getProductBookedDate(resourceId, month)); } /** diff --git a/src/main/java/com/example/pladialmserver/product/resource/service/ResourceService.java b/src/main/java/com/example/pladialmserver/product/resource/service/ResourceService.java index d2031271..e521d3b8 100644 --- a/src/main/java/com/example/pladialmserver/product/resource/service/ResourceService.java +++ b/src/main/java/com/example/pladialmserver/product/resource/service/ResourceService.java @@ -83,12 +83,12 @@ public ProductDetailRes getProductDetail(Long resourceId) { * 장비 기간별 예약 현황 조회 */ @Override - public List getProductBookedDate(Long resourceId, String month, LocalDate date) { + public List getProductBookedDate(Long resourceId, String month) { Resource resource = resourceRepository.findById(resourceId) .orElseThrow(() -> new BaseException(BaseResponseCode.RESOURCE_NOT_FOUND)); // 예약 현황 조회할 월 LocalDate standardDate = DateTimeUtil.stringToFirstLocalDate(month); - return resourceBookingRepository.getResourceBookedDate(resource, standardDate, date); + return resourceBookingRepository.getResourceBookedDate(resource, standardDate); } diff --git a/src/main/java/com/example/pladialmserver/product/service/ProductService.java b/src/main/java/com/example/pladialmserver/product/service/ProductService.java index a5c0791e..d668799a 100644 --- a/src/main/java/com/example/pladialmserver/product/service/ProductService.java +++ b/src/main/java/com/example/pladialmserver/product/service/ProductService.java @@ -19,7 +19,7 @@ public interface ProductService { ProductBookingRes getProductBookingByDate(Long carId, LocalDateTime dateTime); - List getProductBookedDate(Long carId, String month, LocalDate date); + List getProductBookedDate(Long carId, String month); Page getResourcesByAdmin(User user, String keyword, Pageable pageable);