diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/constant/ReservationValidationConstants.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/constant/ReservationValidationConstants.java new file mode 100644 index 00000000..98d07503 --- /dev/null +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/constant/ReservationValidationConstants.java @@ -0,0 +1,20 @@ +package com.fc.shimpyo_be.domain.reservation.constant; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ReservationValidationConstants { + + // regex + public static final String DATE_REGEX = "^\\d{4}-\\d{2}-\\d{2}$"; + public static final int RESERVATION_REQ_MIN_SIZE = 1; + public static final int RESERVATION_REQ_MAX_SIZE = 3; + public static final int TOTAL_PRICE_MIN_VALUE = 0; + + // validation message + public static final String DATE_PATTERN_MESSAGE = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)"; + public static final String RESERVATION_REQ_SIZE_MESSAGE = "최소 1개, 최대 3개의 객실 예약이 가능합니다."; + public static final String PAYMETHOD_NOTNULL_MESSAGE = "null 일 수 없습니다. 정해진 결제 수단에서 선택하세요."; + public static final String TOTAL_PRICE_MIN_MESSAGE = "총 결제 금액은 최소 0원 이상이어야 합니다."; +} diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/controller/ReservationRestController.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/controller/ReservationRestController.java index 3fdb4e6e..fbce2b09 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/controller/ReservationRestController.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/controller/ReservationRestController.java @@ -3,6 +3,7 @@ import com.fc.shimpyo_be.domain.reservation.dto.request.PreoccupyRoomsRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.request.ReleaseRoomsRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.request.SaveReservationRequestDto; +import com.fc.shimpyo_be.domain.reservation.dto.response.ReservationInfoResponseDto; import com.fc.shimpyo_be.domain.reservation.dto.response.SaveReservationResponseDto; import com.fc.shimpyo_be.domain.reservation.dto.response.ValidatePreoccupyResultResponseDto; import com.fc.shimpyo_be.domain.reservation.facade.PreoccupyRoomsLockFacade; @@ -31,12 +32,14 @@ public class ReservationRestController { private final PreoccupyRoomsLockFacade preoccupyRoomsLockFacade; private final ReservationLockFacade reservationLockFacade; private final SecurityUtil securityUtil; + private static final int PAGE_SIZE = 10; + private static final int PAGE_NUM = 0; + private static final String PAGE_SORT_BY = "id"; @PostMapping public ResponseEntity> saveReservation( @Valid @RequestBody SaveReservationRequestDto request ) { - log.debug("[api][POST] /api/reservations"); return ResponseEntity .status(HttpStatus.CREATED) @@ -50,10 +53,9 @@ public ResponseEntity> saveReservation( } @GetMapping - public ResponseEntity>> getReservationList( - @PageableDefault(size = 10, page = 0, sort = "id", direction = Sort.Direction.DESC) Pageable pageable + public ResponseEntity>> getReservationList( + @PageableDefault(size = PAGE_SIZE, page = PAGE_NUM, sort = PAGE_SORT_BY, direction = Sort.Direction.DESC) Pageable pageable ) { - log.debug("[api][GET] /api/reservations"); return ResponseEntity .status(HttpStatus.OK) @@ -70,7 +72,6 @@ public ResponseEntity>> getReservationList( public ResponseEntity> checkAvailableAndPreoccupy( @Valid @RequestBody PreoccupyRoomsRequestDto request ) { - log.debug("[api][POST] /api/reservations/preoccupy"); return ResponseEntity .status(HttpStatus.OK) @@ -87,7 +88,6 @@ public ResponseEntity> checkAvai public ResponseEntity> releaseRooms( @Valid @RequestBody ReleaseRoomsRequestDto request ) { - log.debug("[api][POST] /api/reservations/release"); reservationService.releaseRooms(securityUtil.getCurrentMemberId(), request); diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomItemRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomItemRequestDto.java index 09b90452..9d6aa745 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomItemRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomItemRequestDto.java @@ -4,15 +4,17 @@ import jakarta.validation.constraints.Pattern; import lombok.Builder; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; + @Builder public record PreoccupyRoomItemRequestDto( @NotNull Long cartId, @NotNull Long roomCode, - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = DATE_PATTERN_MESSAGE) String startDate, - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = DATE_PATTERN_MESSAGE) String endDate ) { } diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomsRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomsRequestDto.java index c8e0b97e..35080845 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomsRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/PreoccupyRoomsRequestDto.java @@ -6,11 +6,12 @@ import java.util.List; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; + @Builder public record PreoccupyRoomsRequestDto( - @Valid - @Size(min = 1, max = 3, message = "최소 1개, 최대 3개의 객실 예약이 가능합니다.") + @Size(min = RESERVATION_REQ_MIN_SIZE, max = RESERVATION_REQ_MAX_SIZE, message = RESERVATION_REQ_SIZE_MESSAGE) List rooms ) { } diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomItemRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomItemRequestDto.java index 5c46bb16..46c2d3d7 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomItemRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomItemRequestDto.java @@ -4,13 +4,15 @@ import jakarta.validation.constraints.Pattern; import lombok.Builder; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; + @Builder public record ReleaseRoomItemRequestDto( @NotNull Long roomId, - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = DATE_PATTERN_MESSAGE) String startDate, - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = DATE_PATTERN_MESSAGE) String endDate ) { } diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomsRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomsRequestDto.java index ca1d809a..d421e828 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomsRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/ReleaseRoomsRequestDto.java @@ -6,10 +6,12 @@ import java.util.List; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; + @Builder public record ReleaseRoomsRequestDto( @Valid - @Size(min = 1, max = 3, message = "최소 1개, 최대 3개의 객실 요청 정보가 필요합니다.") + @Size(min = RESERVATION_REQ_MIN_SIZE, max = RESERVATION_REQ_MAX_SIZE, message = RESERVATION_REQ_SIZE_MESSAGE) List rooms ) { } diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/SaveReservationRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/SaveReservationRequestDto.java index 458d1340..220cf3bc 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/SaveReservationRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/request/SaveReservationRequestDto.java @@ -10,14 +10,16 @@ import java.util.List; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; + @Builder public record SaveReservationRequestDto( @Valid - @Size(min = 1, max = 3, message = "최소 1개, 최대 3개의 객실 예약이 가능합니다.") + @Size(min = RESERVATION_REQ_MIN_SIZE, max = RESERVATION_REQ_MAX_SIZE, message = RESERVATION_REQ_SIZE_MESSAGE) List reservationProducts, - @NotNull(message = "null 일 수 없습니다. 정해진 결제 수단에서 선택하세요.") + @NotNull(message = PAYMETHOD_NOTNULL_MESSAGE) PayMethod payMethod, - @Min(value = 0, message = "총 결제 금액은 음수일 수 없습니다.") + @Min(value = TOTAL_PRICE_MIN_VALUE, message = TOTAL_PRICE_MIN_MESSAGE) Integer totalPrice ) { } diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/entity/Reservation.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/entity/Reservation.java index 6f435cbe..c904a365 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/entity/Reservation.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/entity/Reservation.java @@ -39,7 +39,7 @@ public class Reservation extends BaseTimeEntity { private List reservationProducts = new ArrayList<>(); @Builder - public Reservation( + private Reservation( Long id, Member member, PayMethod payMethod, diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/InvalidRequestException.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/InvalidRequestException.java deleted file mode 100644 index 1991b6f6..00000000 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/InvalidRequestException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fc.shimpyo_be.domain.reservation.exception; - -import com.fc.shimpyo_be.global.exception.ApplicationException; -import com.fc.shimpyo_be.global.exception.ErrorCode; - -public class InvalidRequestException extends ApplicationException { - - public InvalidRequestException(ErrorCode errorCode) { - super(errorCode); - } -} diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/PreoccupyRoomsLockFacade.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/PreoccupyRoomsLockFacade.java index e3cb3df2..81892b32 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/PreoccupyRoomsLockFacade.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/PreoccupyRoomsLockFacade.java @@ -38,7 +38,6 @@ public ValidatePreoccupyResultResponseDto checkAvailableAndPreoccupy(Long member CheckAvailableRoomsResultDto resultDto = preoccupyRoomsService.checkAvailable(memberId, request); if(!resultDto.isAvailable()) { - log.debug("[{}][check available rooms result] isAvailable = {}, results = {}", currentWorker, false, resultDto.roomResults()); throw new PreoccupyNotAvailableException( ValidatePreoccupyResultResponseDto.builder() .isAvailable(false) @@ -47,8 +46,6 @@ public ValidatePreoccupyResultResponseDto checkAvailableAndPreoccupy(Long member ); } - log.debug("[{}][check available rooms result] isAvailable = {}, results = {}", currentWorker, true, resultDto.roomResults()); - log.debug("[{}][check available rooms result] preoccupyMap = {}", currentWorker, resultDto.preoccupyMap()); preoccupyRoomsService.preoccupy(resultDto); return ValidatePreoccupyResultResponseDto.builder() diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/ReservationLockFacade.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/ReservationLockFacade.java index bf136498..27615b04 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/ReservationLockFacade.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/ReservationLockFacade.java @@ -28,7 +28,7 @@ public SaveReservationResponseDto saveReservation(Long memberId, SaveReservation String currentWorker = Thread.currentThread().getName(); try { - boolean isLocked = lock.tryLock(2, 4, TimeUnit.SECONDS); + boolean isLocked = lock.tryLock(3, 5, TimeUnit.SECONDS); if(!isLocked) { log.error("[{}] 예약 lock 획득 실패", currentWorker); @@ -38,8 +38,6 @@ public SaveReservationResponseDto saveReservation(Long memberId, SaveReservation ValidateReservationResultDto resultDto = reservationService.validate(memberId, request.reservationProducts()); if(!resultDto.isAvailable()) { - log.debug("[{}][validate rooms result] isAvailable = {}, unavailableIds = {}", currentWorker, false, resultDto.unavailableIds()); - throw new ReserveNotAvailableException( ValidateReservationResultResponseDto.builder() .isAvailable(false) @@ -48,8 +46,6 @@ public SaveReservationResponseDto saveReservation(Long memberId, SaveReservation ); } - log.debug("[{}][validate rooms result] isAvailable = {}, unavailableIds = {}", currentWorker, true, resultDto.unavailableIds()); - return reservationService.saveReservation(memberId, request, resultDto.confirmMap()); } catch (InterruptedException exception) { diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/service/PreoccupyRoomsService.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/service/PreoccupyRoomsService.java index c352c409..9c584d94 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/service/PreoccupyRoomsService.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/service/PreoccupyRoomsService.java @@ -60,7 +60,6 @@ public CheckAvailableRoomsResultDto checkAvailable(Long memberId, PreoccupyRooms String key = String.format(PREOCCUPY_REDIS_KEY_FORMAT, roomId, targetDate); Object value = opsForValue.get(key); - log.info("roomId: {}, targetDate: {}, value: {}", roomId, targetDate, value); if(Objects.nonNull(value)) { dateCheck = false; preoccupyMap.remove(roomId); diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/service/ReservationService.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/service/ReservationService.java index eda97096..6e2c7371 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/service/ReservationService.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/service/ReservationService.java @@ -3,7 +3,6 @@ import com.fc.shimpyo_be.domain.cart.service.CartService; import com.fc.shimpyo_be.domain.member.entity.Member; import com.fc.shimpyo_be.domain.member.service.MemberService; -import com.fc.shimpyo_be.domain.product.exception.RoomNotFoundException; import com.fc.shimpyo_be.domain.reservation.dto.ValidateReservationResultDto; import com.fc.shimpyo_be.domain.reservation.dto.request.ReleaseRoomItemRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.request.ReleaseRoomsRequestDto; @@ -12,12 +11,12 @@ import com.fc.shimpyo_be.domain.reservation.dto.response.SaveReservationResponseDto; import com.fc.shimpyo_be.domain.reservation.entity.Reservation; import com.fc.shimpyo_be.domain.reservation.repository.ReservationRepository; -import com.fc.shimpyo_be.domain.reservation.util.ReservationMapper; +import com.fc.shimpyo_be.domain.reservation.util.mapper.ReservationMapper; import com.fc.shimpyo_be.domain.reservationproduct.dto.request.ReservationProductRequestDto; import com.fc.shimpyo_be.domain.reservationproduct.entity.ReservationProduct; import com.fc.shimpyo_be.domain.reservationproduct.repository.ReservationProductRepository; import com.fc.shimpyo_be.domain.room.entity.Room; -import com.fc.shimpyo_be.domain.room.repository.RoomRepository; +import com.fc.shimpyo_be.domain.room.service.RoomService; import com.fc.shimpyo_be.global.util.DateTimeUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -41,7 +40,7 @@ public class ReservationService { private final ReservationRepository reservationRepository; private final ReservationProductRepository reservationProductRepository; private final MemberService memberService; - private final RoomRepository roomRepository; + private final RoomService roomService; private final CartService cartService; private final RedisTemplate redisTemplate; private static final String REDIS_ROOM_KEY_FORMAT = "roomId:%d:%s"; @@ -50,7 +49,6 @@ public class ReservationService { public SaveReservationResponseDto saveReservation( Long memberId, SaveReservationRequestDto request, Map> reservationMap ) { - log.debug("{} ::: {}", getClass().getSimpleName(), "saveReservation"); // 회원 엔티티 조회 Member member = memberService.getMemberById(memberId); @@ -59,8 +57,7 @@ public SaveReservationResponseDto saveReservation( List reservationProducts = new ArrayList<>(); for (ReservationProductRequestDto reservationProductDto : request.reservationProducts()) { - Room room = roomRepository.findById(reservationProductDto.roomId()) - .orElseThrow(RoomNotFoundException::new); + Room room = roomService.getRoomById(reservationProductDto.roomId()); // 장바구니 아이템 삭제 if (reservationProductDto.cartId() > 0) { @@ -96,7 +93,6 @@ public SaveReservationResponseDto saveReservation( @Transactional(readOnly = true) public Page getReservationInfoList(Long memberId, Pageable pageable) { - log.debug("{} ::: {}", getClass().getSimpleName(), "getReservationInfoList"); List reservationIds = reservationRepository.findIdsByMemberId(memberId); @@ -106,7 +102,6 @@ public Page getReservationInfoList(Long memberId, Pa } public ValidateReservationResultDto validate(Long memberId, List reservationProducts) { - log.debug("{} ::: {}", getClass().getSimpleName(), "validate"); ValueOperations opsForValue = redisTemplate.opsForValue(); @@ -155,7 +150,6 @@ public ValidateReservationResultDto validate(Long memberId, List opsForValue = redisTemplate.opsForValue(); @@ -180,7 +174,6 @@ public void releaseRooms(Long memberId, ReleaseRoomsRequestDto request) { } private void confirmReservationProduct(List reservationKeys, String endDate) { - log.debug("{} ::: {}", getClass().getSimpleName(), "confirmReservationProduct"); Date expireDate = convertLocalDateToDate(DateTimeUtil.toLocalDate(endDate)); for (String key : reservationKeys) { diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/util/ReservationMapper.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/util/mapper/ReservationMapper.java similarity index 98% rename from src/main/java/com/fc/shimpyo_be/domain/reservation/util/ReservationMapper.java rename to src/main/java/com/fc/shimpyo_be/domain/reservation/util/mapper/ReservationMapper.java index 0c5d3daa..5ad17e62 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/util/ReservationMapper.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/util/mapper/ReservationMapper.java @@ -1,4 +1,4 @@ -package com.fc.shimpyo_be.domain.reservation.util; +package com.fc.shimpyo_be.domain.reservation.util.mapper; import com.fc.shimpyo_be.domain.product.entity.Product; import com.fc.shimpyo_be.domain.reservation.dto.response.ReservationInfoResponseDto; diff --git a/src/main/java/com/fc/shimpyo_be/domain/product/exception/RoomNotFoundException.java b/src/main/java/com/fc/shimpyo_be/domain/room/exception/RoomNotFoundException.java similarity index 83% rename from src/main/java/com/fc/shimpyo_be/domain/product/exception/RoomNotFoundException.java rename to src/main/java/com/fc/shimpyo_be/domain/room/exception/RoomNotFoundException.java index 6afb1ae5..02d5d673 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/product/exception/RoomNotFoundException.java +++ b/src/main/java/com/fc/shimpyo_be/domain/room/exception/RoomNotFoundException.java @@ -1,4 +1,4 @@ -package com.fc.shimpyo_be.domain.product.exception; +package com.fc.shimpyo_be.domain.room.exception; import com.fc.shimpyo_be.global.exception.ApplicationException; import com.fc.shimpyo_be.global.exception.ErrorCode; diff --git a/src/main/java/com/fc/shimpyo_be/domain/room/service/RoomService.java b/src/main/java/com/fc/shimpyo_be/domain/room/service/RoomService.java index f5fa36ac..87cb8142 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/room/service/RoomService.java +++ b/src/main/java/com/fc/shimpyo_be/domain/room/service/RoomService.java @@ -1,6 +1,8 @@ package com.fc.shimpyo_be.domain.room.service; +import com.fc.shimpyo_be.domain.room.exception.RoomNotFoundException; import com.fc.shimpyo_be.domain.room.dto.response.RoomWithProductResponseDto; +import com.fc.shimpyo_be.domain.room.entity.Room; import com.fc.shimpyo_be.domain.room.repository.RoomRepository; import com.fc.shimpyo_be.domain.room.util.RoomMapper; import lombok.RequiredArgsConstructor; @@ -31,4 +33,10 @@ public List getRoomIdsByCode(Long roomCode) { return roomRepository.findIdsByCode(roomCode); } + + @Transactional(readOnly = true) + public Room getRoomById(Long id) { + return roomRepository.findById(id) + .orElseThrow(RoomNotFoundException::new); + } } diff --git a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/GetReservationListServiceTest.java b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/GetReservationListServiceTest.java index c94bd3e7..b87db936 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/GetReservationListServiceTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/GetReservationListServiceTest.java @@ -80,8 +80,107 @@ void setUp() { .build() ); + List products = getProductTestDataList(3); + List rooms = getRoomTestDataList(5, products); + + Reservation reservation1 = reservationRepository.save( + Reservation.builder() + .reservationProducts( + List.of( + getReservationProduct( + rooms.get(0), + LocalDate.of(2023, 11, 10), + LocalDate.of(2023, 11, 12), + 200000 + ), + getReservationProduct( + rooms.get(1), + LocalDate.of(2023, 11, 20), + LocalDate.of(2023, 11, 22), + 200000 + ) + ) + ) + .member(member) + .payMethod(PayMethod.CREDIT_CARD) + .totalPrice(400000) + .build() + ); + + Reservation reservation2 = reservationRepository.save( + Reservation.builder() + .reservationProducts( + List.of( + getReservationProduct( + rooms.get(2), + LocalDate.of(2023, 12, 4), + LocalDate.of(2023, 12, 7), + 300000 + ) + ) + ) + .totalPrice(300000) + .payMethod(PayMethod.KAKAO_PAY) + .member(member) + .build() + ); + + Reservation reservation3 = reservationRepository.save( + Reservation.builder() + .reservationProducts( + List.of( + getReservationProduct( + rooms.get(1), + LocalDate.of(2023, 12, 15), + LocalDate.of(2023, 12, 18), + 360000 + ), + getReservationProduct( + rooms.get(2), + LocalDate.of(2024, 1, 10), + LocalDate.of(2024, 1, 12), + 240000 + ) + ) + ) + .member(member) + .payMethod(PayMethod.CREDIT_CARD) + .totalPrice(600000) + .build() + ); + } + + @DisplayName("전체 주문 목록을 정상적으로 페이징 조회할 수 있다.") + @Test + void getReservationInfoList_test() { + //given + long memberId = member.getId(); + PageRequest pageRequest = PageRequest.of(0, 2); + + //when + Page result = reservationService.getReservationInfoList(memberId, pageRequest); + + //then + assertThat(result.getTotalElements()).isEqualTo(5); + assertThat(result.getTotalPages()).isEqualTo(3); + log.info("{}", result.getContent().get(0)); + } + + private ReservationProduct getReservationProduct(Room room, LocalDate startDate, LocalDate endDate, int price) { + return ReservationProduct.builder() + .room(room) + .startDate(startDate) + .endDate(endDate) + .visitorName("방문자명") + .visitorPhone("010-1111-1111") + .price(price) + .build(); + } + + private List getProductTestDataList(int size) { List products = new ArrayList<>(); - for (int i = 1; i <= 3; i++) { + + for (int i = 1; i <= size; i++) { String productName = "호텔" + i; float starAvg = ThreadLocalRandom.current().nextFloat(0, 5); String infoCenter = String.format("02-1234-%d%d%d%d", i, i, i, i); @@ -130,13 +229,18 @@ void setUp() { ); } + return products; + } + + private List getRoomTestDataList(int size, List products) { List rooms = new ArrayList<>(); - for (int i = 1; i <= 5; i++) { + for (int i = 1; i <= size; i++) { String roomName = "객실" + i; rooms.add( roomRepository.save( Room.builder() - .product(products.get((i - 1) % 3)) + .code(1000 + i) + .product(products.get((i - 1) % products.size())) .name(roomName) .description(roomName + " 설명") .standard(2) @@ -174,96 +278,6 @@ void setUp() { ); } - Reservation reservation1 = reservationRepository.save( - Reservation.builder() - .reservationProducts( - List.of( - ReservationProduct.builder() - .room(rooms.get(0)) - .startDate(LocalDate.of(2023, 11, 10)) - .endDate(LocalDate.of(2023, 11, 12)) - .visitorName("방문자명") - .visitorPhone("010-1111-1111") - .price(200000) - .build(), - ReservationProduct.builder() - .room(rooms.get(1)) - .startDate(LocalDate.of(2023, 11, 20)) - .endDate(LocalDate.of(2023, 11, 22)) - .visitorName("방문자명") - .visitorPhone("010-1111-1111") - .price(200000) - .build() - ) - ) - .member(member) - .payMethod(PayMethod.CREDIT_CARD) - .totalPrice(400000) - .build() - ); - - Reservation reservation2 = reservationRepository.save( - Reservation.builder() - .reservationProducts( - List.of( - ReservationProduct.builder() - .room(rooms.get(2)) - .startDate(LocalDate.of(2023, 12, 4)) - .endDate(LocalDate.of(2023, 12, 7)) - .visitorName("방문자명") - .visitorPhone("010-1111-1111") - .price(300000) - .build() - ) - ) - .totalPrice(300000) - .payMethod(PayMethod.KAKAO_PAY) - .member(member) - .build() - ); - - Reservation reservation3 = reservationRepository.save( - Reservation.builder() - .reservationProducts( - List.of( - ReservationProduct.builder() - .room(rooms.get(1)) - .startDate(LocalDate.of(2023, 12, 15)) - .endDate(LocalDate.of(2023, 12, 18)) - .visitorName("방문자명") - .visitorPhone("010-1111-1111") - .price(360000) - .build(), - ReservationProduct.builder() - .room(rooms.get(2)) - .startDate(LocalDate.of(2024, 1, 10)) - .endDate(LocalDate.of(2024, 1, 12)) - .visitorName("방문자명") - .visitorPhone("010-1111-1111") - .price(240000) - .build() - ) - ) - .member(member) - .payMethod(PayMethod.CREDIT_CARD) - .totalPrice(600000) - .build() - ); - } - - @DisplayName("전체 주문 목록을 정상적으로 페이징 조회할 수 있다.") - @Test - void getReservationInfoList_test() { - //given - long memberId = member.getId(); - PageRequest pageRequest = PageRequest.of(0, 2); - - //when - Page result = reservationService.getReservationInfoList(memberId, pageRequest); - - //then - assertThat(result.getTotalElements()).isEqualTo(5); - assertThat(result.getTotalPages()).isEqualTo(3); - log.info("{}", result.getContent().get(0)); + return rooms; } } diff --git a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/ReservationServiceTest.java b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/ReservationServiceTest.java index f1045ccb..30cb9cec 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/ReservationServiceTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/service/ReservationServiceTest.java @@ -10,7 +10,7 @@ import com.fc.shimpyo_be.domain.member.exception.MemberNotFoundException; import com.fc.shimpyo_be.domain.member.repository.MemberRepository; import com.fc.shimpyo_be.domain.product.entity.*; -import com.fc.shimpyo_be.domain.product.exception.RoomNotFoundException; +import com.fc.shimpyo_be.domain.room.exception.RoomNotFoundException; import com.fc.shimpyo_be.domain.product.repository.ProductRepository; import com.fc.shimpyo_be.domain.reservation.dto.request.SaveReservationRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.response.SaveReservationResponseDto; @@ -89,100 +89,8 @@ void setUp() { .build() ); - List products = new ArrayList<>(); - for (int i = 1; i <= 3; i++) { - String productName = "호텔" + i; - float starAvg = ThreadLocalRandom.current().nextFloat(0, 5); - String infoCenter = String.format("02-1234-%d%d%d%d", i, i, i, i); - products.add( - productRepository.save( - Product.builder() - .name(productName) - .thumbnail(productName + " 썸네일 url") - .description(productName + " 설명") - .starAvg(starAvg) - .category(Category.TOURIST_HOTEL) - .address( - Address.builder() - .address(productName + " 주소") - .detailAddress(productName + " 상세 주소") - .mapX(1.0) - .mapY(1.5) - .build() - ) - .productOption( - ProductOption.builder() - .cooking(true) - .foodPlace("음료 가능") - .parking(true) - .pickup(false) - .infoCenter(infoCenter) - .build() - ) - .amenity( - Amenity.builder() - .barbecue(false) - .beauty(true) - .beverage(true) - .fitness(true) - .bicycle(false) - .campfire(false) - .karaoke(true) - .publicBath(true) - .publicPc(true) - .seminar(false) - .sports(false) - .build() - ) - .build() - ) - ); - } - - List rooms = new ArrayList<>(); - for (int i = 1; i <= 3; i++) { - String roomName = "객실" + i; - rooms.add( - roomRepository.save( - Room.builder() - .code(1000 + i) - .product(products.get(i - 1)) - .name(roomName) - .description(roomName + " 설명") - .standard(2) - .capacity(4) - .checkIn(LocalTime.of(14, 0)) - .checkOut(LocalTime.of(12, 0)) - .price( - RoomPrice.builder() - .offWeekDaysMinFee(75000) - .offWeekendMinFee(85000) - .peakWeekDaysMinFee(100000) - .peakWeekendMinFee(120000) - .build() - ) - .roomOption( - RoomOption.builder() - .cooking(true) - .airCondition(true) - .bath(true) - .bathFacility(true) - .pc(false) - .diningTable(true) - .hairDryer(true) - .homeTheater(false) - .internet(true) - .cable(false) - .refrigerator(true) - .sofa(true) - .toiletries(true) - .tv(true) - .build() - ) - .build() - ) - ); - } + List products = getProductTestDataList(3); + List rooms = getRoomTestDataList(3, products); cartRepository.save( Cart.builder() @@ -358,4 +266,108 @@ private List getKeyList(Long roomId, String startDate, String endDate) { return keyList; } + + private List getProductTestDataList(int size) { + List products = new ArrayList<>(); + + for (int i = 1; i <= size; i++) { + String productName = "호텔" + i; + float starAvg = ThreadLocalRandom.current().nextFloat(0, 5); + String infoCenter = String.format("02-1234-%d%d%d%d", i, i, i, i); + products.add( + productRepository.save( + Product.builder() + .name(productName) + .thumbnail(productName + " 썸네일 url") + .description(productName + " 설명") + .starAvg(starAvg) + .category(Category.TOURIST_HOTEL) + .address( + Address.builder() + .address(productName + " 주소") + .detailAddress(productName + " 상세 주소") + .mapX(1.0) + .mapY(1.5) + .build() + ) + .productOption( + ProductOption.builder() + .cooking(true) + .foodPlace("음료 가능") + .parking(true) + .pickup(false) + .infoCenter(infoCenter) + .build() + ) + .amenity( + Amenity.builder() + .barbecue(false) + .beauty(true) + .beverage(true) + .fitness(true) + .bicycle(false) + .campfire(false) + .karaoke(true) + .publicBath(true) + .publicPc(true) + .seminar(false) + .sports(false) + .build() + ) + .build() + ) + ); + } + + return products; + } + + private List getRoomTestDataList(int size, List products) { + List rooms = new ArrayList<>(); + for (int i = 1; i <= size; i++) { + String roomName = "객실" + i; + rooms.add( + roomRepository.save( + Room.builder() + .code(1000 + i) + .product(products.get((i - 1) % products.size())) + .name(roomName) + .description(roomName + " 설명") + .standard(2) + .capacity(4) + .checkIn(LocalTime.of(14, 0)) + .checkOut(LocalTime.of(12, 0)) + .price( + RoomPrice.builder() + .offWeekDaysMinFee(75000) + .offWeekendMinFee(85000) + .peakWeekDaysMinFee(100000) + .peakWeekendMinFee(120000) + .build() + ) + .roomOption( + RoomOption.builder() + .cooking(true) + .airCondition(true) + .bath(true) + .bathFacility(true) + .pc(false) + .diningTable(true) + .hairDryer(true) + .homeTheater(false) + .internet(true) + .cable(false) + .refrigerator(true) + .sofa(true) + .toiletries(true) + .tv(true) + .build() + ) + .build() + ) + ); + } + + return rooms; + } }