Skip to content

Commit

Permalink
Merge pull request #227 from PLADI-ALM/feat/PDS-197-getResourceBooked…
Browse files Browse the repository at this point in the history
…Info

[PDS-197/feat] 해당 날짜의 예약된 정보 조회 API
  • Loading branch information
leeseunghakhello authored Nov 24, 2023
2 parents bf91579 + ec02412 commit 3ee3a62
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.pladialmserver.booking.repository.carBooking;

import com.example.pladialmserver.booking.dto.response.BookingRes;
import com.example.pladialmserver.product.car.dto.CarRes;
import com.example.pladialmserver.product.car.entity.Car;
import com.example.pladialmserver.product.dto.response.ProductBookingRes;
import com.example.pladialmserver.user.entity.User;
Expand All @@ -24,4 +23,6 @@ public interface CarBookingCustom {
List<Long> findBookedCarIdsByDate(LocalDateTime startDate, LocalDateTime endDate);

List<String> getBookedTime(Car car, LocalDate date);

List<ProductBookingRes> findCarBookingByDate(Car car, LocalDate date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,25 @@ public List<String> getBookedTime(Car car, LocalDate standardDate) {

return answer;
}

@Override
public List<ProductBookingRes> findCarBookingByDate(Car car, LocalDate standardDate) {
// 기준 날짜의 첫 시간 (00:00)
LocalDateTime startDateTime = standardDate.atStartOfDay();
// 기준 날짜의 마지막 시간 (23:00)
LocalDateTime endDateTime = standardDate.atTime(23, 0);

// 기준 날짜에 포함된 예약
List<CarBooking> bookings = jpaQueryFactory.selectFrom(carBooking)
.where(carBooking.car.eq(car)
.and(carBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING))
.and(carBooking.startDate.before(endDateTime)
.and(carBooking.endDate.after(startDateTime))
.or(carBooking.startDate.before(startDateTime).and(carBooking.endDate.after(endDateTime)))
)
).orderBy(carBooking.startDate.asc())
.fetch();

return bookings.stream().map(ProductBookingRes::toDto).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface ResourceBookingCustom {
List<Long> findBookedResourceIdsByDate(LocalDateTime startDate, LocalDateTime endDate);

List<String> getBookedTime(Resource resource, LocalDate date);

List<ProductBookingRes> findResourceBookingByDate(Resource resource, LocalDate date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,25 @@ public List<String> getBookedTime(Resource resource, LocalDate standardDate) {

return answer;
}

@Override
public List<ProductBookingRes> findResourceBookingByDate(Resource resource, LocalDate standardDate) {
// 기준 날짜의 첫 시간 (00:00)
LocalDateTime startDateTime = standardDate.atStartOfDay();
// 기준 날짜의 마지막 시간 (23:00)
LocalDateTime endDateTime = standardDate.atTime(23, 0);

// 기준 날짜에 포함된 예약
List<ResourceBooking> bookings = jpaQueryFactory.selectFrom(resourceBooking)
.where(resourceBooking.resource.eq(resource)
.and(resourceBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING))
.and(resourceBooking.startDate.before(endDateTime)
.and(resourceBooking.endDate.after(startDateTime))
.or(resourceBooking.startDate.before(startDateTime).and(resourceBooking.endDate.after(endDateTime)))
)
).orderBy(resourceBooking.startDate.asc())
.fetch();

return bookings.stream().map(ProductBookingRes::toDto).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ public ResponseCustom<List<String>> getCarBookedTime(
return ResponseCustom.OK(carService.getProductBookedTime(resourceId, date));
}

/**
* 해당 날짜의 차량 예약된 정보 조회
*/
@Operation(summary = "해당 날짜의 차량 예약된 정보 조회 (박소정)", description = "해당 날짜의 차량 예약된 정보 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
@ApiResponse(responseCode = "400", description = "(C0001)존재하지 않는 차량입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@GetMapping("/{carId}/booking-info")
public ResponseCustom<List<ProductBookingRes>> getCarBookedInfo(
@Account User user,
@Parameter(description = "(Long) 차량 Id", example = "1") @PathVariable(name = "carId") Long carId,
@Parameter(description = "장비 예약 현황 조회 날짜 (YYYY-MM-DD)", example = "2023-10-23") @RequestParam(required = false) @DateTimeFormat(pattern = DATE_PATTERN) LocalDate date) {
return ResponseCustom.OK(carService.getProductBookedInfo(carId, date));
}

/**
* 차량 월별 예약 현황 조회
*/
Expand All @@ -148,8 +164,7 @@ public ResponseCustom<List<String>> getCarBookedTime(
public ResponseCustom<List<String>> getCarBookedDate(
@Account User user,
@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) {
@Parameter(description = "차량 예약 현황 조회 년도월 (YYYY-MM)", example = "2023-10") @RequestParam String month) {
return ResponseCustom.OK(carService.getProductBookedDate(carId, month));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ public void activateProductByAdmin(User user, Long carId) {
car.activateResource();
}

@Override
public List<ProductBookingRes> getProductBookedInfo(Long carId, LocalDate date) {
// 차량 유무 확인
Car car = carRepository.findById(carId)
.orElseThrow(() -> new BaseException(BaseResponseCode.CAR_NOT_FOUND));
return carBookingRepository.findCarBookingByDate(car, date);
}

// 관리자 권한 확인
private void checkAdminRole(User user) {
if(!user.checkRole(Role.ADMIN)) throw new BaseException(BaseResponseCode.NO_AUTHENTICATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ public ResponseCustom<List<String>> getResourceBookedTime(
return ResponseCustom.OK(resourceService.getProductBookedTime(resourceId, date));
}

/**
* 해당 날짜의 장비 예약된 정보 조회
*/
@Operation(summary = "해당 날짜의 장비 예약된 정보 조회 (박소정)", description = "해당 날짜의 장비 예약된 정보 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
@ApiResponse(responseCode = "400", description = "(R0003)존재하지 않는 장비입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@GetMapping("/{resourceId}/booking-info")
public ResponseCustom<List<ProductBookingRes>> getResourceBookedInfo(
@Account User user,
@Parameter(description = "(Long) 장비 Id", example = "1") @PathVariable(name = "resourceId") Long resourceId,
@Parameter(description = "장비 예약 현황 조회 날짜 (YYYY-MM-DD)", example = "2023-10-23") @RequestParam(required = false) @DateTimeFormat(pattern = DATE_PATTERN) LocalDate date) {
return ResponseCustom.OK(resourceService.getProductBookedInfo(resourceId, date));
}


/**
* 장비 예약
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,15 @@ public void activateProductByAdmin(User user, Long resourceId) {
resource.activateResource();
}

// 해당 날짜의 장비 예약 내역 조회
@Override
public List<ProductBookingRes> getProductBookedInfo(Long resourceId, LocalDate date) {
// 장비 유무 확인
Resource resource = resourceRepository.findById(resourceId)
.orElseThrow(() -> new BaseException(BaseResponseCode.RESOURCE_NOT_FOUND));
return resourceBookingRepository.findResourceBookingByDate(resource, date);
}

// 해당 일시의 장비 예약 내역 조회
@Override
public ProductBookingRes getProductBookingByDate(Long resourceId, LocalDateTime dateTime) {
// 장비 유무 확인
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface ProductService {
AdminProductDetailsRes getAdminProductsDetails(User user, Long productId);

void activateProductByAdmin(User user, Long productId);

List<ProductBookingRes> getProductBookedInfo(Long productId, LocalDate date);
}

0 comments on commit 3ee3a62

Please sign in to comment.