From e257fe85579b6dc6b39237959d1200dab722fb9e Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 23:52:54 +0900 Subject: [PATCH 01/15] =?UTF-8?q?refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EB=B0=8F=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationValidationConstants.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java new file mode 100644 index 0000000..57e95df --- /dev/null +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java @@ -0,0 +1,20 @@ +package com.fc.shimpyo_be.domain.reservation.util.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 Integer RESERVATION_REQ_MIN_SIZE = 1; + public static final Integer RESERVATION_REQ_MAX_SIZE = 3; + public static final Integer 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원 이상이어야 합니다."; +} From 4372274dcb84a2f5399588e155b4f8b26fe49ca5 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 23:54:05 +0900 Subject: [PATCH 02/15] =?UTF-8?q?refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20Request=20DTO=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=83=81=EC=88=98=ED=99=94=ED=95=9C=20=EA=B2=83=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/PreoccupyRoomItemRequestDto.java | 6 ++++-- .../reservation/dto/request/PreoccupyRoomsRequestDto.java | 5 +++-- .../dto/request/ReleaseRoomItemRequestDto.java | 6 ++++-- .../reservation/dto/request/ReleaseRoomsRequestDto.java | 4 +++- .../dto/request/SaveReservationRequestDto.java | 8 +++++--- .../dto/request/ReservationProductRequestDto.java | 4 ++++ 6 files changed, 23 insertions(+), 10 deletions(-) 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 09b9045..51b5c77 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.util.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 c8e0b97..9a4bd66 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.util.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 5c46bb1..9276797 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.util.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 = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") String startDate, - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") 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 ca1d809..af63f0d 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.util.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 458d134..bb6ee16 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.util.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/reservationproduct/dto/request/ReservationProductRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservationproduct/dto/request/ReservationProductRequestDto.java index a57bb0f..ed9abad 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservationproduct/dto/request/ReservationProductRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservationproduct/dto/request/ReservationProductRequestDto.java @@ -1,6 +1,7 @@ package com.fc.shimpyo_be.domain.reservationproduct.dto.request; import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import lombok.Builder; @@ -15,7 +16,10 @@ public record ReservationProductRequestDto( String startDate, @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") String endDate, + @NotBlank String visitorName, + @NotBlank + @Pattern(regexp = "^0\\d{1,2}-\\d{3,4}-\\d{4}$") String visitorPhone, @Min(value = 0, message = "객실 이용 금액은 0원 이상부터 가능합니다.") Integer price From fbe654d683c61c1f5ca1b5f6fc5275748fb7dae2 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 23:54:58 +0900 Subject: [PATCH 03/15] =?UTF-8?q?remove:=20=EC=98=88=EC=95=BD=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20Exc?= =?UTF-8?q?eption=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/InvalidRequestException.java | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/main/java/com/fc/shimpyo_be/domain/reservation/exception/InvalidRequestException.java 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 1991b6f..0000000 --- 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); - } -} From d1e2881831aaea7f56382a627bf5722a60ae7c09 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 23:56:16 +0900 Subject: [PATCH 04/15] =?UTF-8?q?refactor:=20Reservation=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20@Builder=20=EC=84=A0=EC=96=B8=ED=95=9C=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=A0=91=EA=B7=BC=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=EC=9E=90=20private=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fc/shimpyo_be/domain/reservation/entity/Reservation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6f435cb..c904a36 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, From 2e05a7006134187fb199405fa30725e8b56ba4db Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 23:58:33 +0900 Subject: [PATCH 05/15] =?UTF-8?q?move:=20ReservationMapper=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - domain/reservation/util/mapper 로 이동 --- .../domain/reservation/util/{ => mapper}/ReservationMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/fc/shimpyo_be/domain/reservation/util/{ => mapper}/ReservationMapper.java (98%) 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 0c5d3da..5ad17e6 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; From a2dda91fff8d9482525908c0b92f7304b1cc8e60 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:00:20 +0900 Subject: [PATCH 06/15] =?UTF-8?q?move:=20RoomNotFoundException=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20Room=20=EB=8F=84=EB=A9=94=EC=9D=B8=20excep?= =?UTF-8?q?tion=20=ED=8C=A8=ED=82=A4=EC=A7=80=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{product => room}/exception/RoomNotFoundException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/fc/shimpyo_be/domain/{product => room}/exception/RoomNotFoundException.java (83%) 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 6afb1ae..02d5d67 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; From d97c251507249fcb04c689e8286d8e88d3b2bbe4 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:01:43 +0900 Subject: [PATCH 07/15] =?UTF-8?q?feat:=20RoomService=EC=97=90=20=EA=B0=9C?= =?UTF-8?q?=EB=B3=84=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20getRoomById?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fc/shimpyo_be/domain/room/service/RoomService.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 a373451..12b77b3 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; @@ -33,4 +35,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); + } } From 9d87029747d3f35d553d483a5b80c9d7292202c3 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:07:14 +0900 Subject: [PATCH 08/15] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20debug=20=EB=A1=9C=EA=B7=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationRestController.java | 4 ---- .../reservation/facade/PreoccupyRoomsLockFacade.java | 3 --- .../domain/reservation/facade/ReservationLockFacade.java | 6 +----- .../reservation/service/PreoccupyRoomsService.java | 1 - .../domain/reservation/service/ReservationService.java | 9 ++------- 5 files changed, 3 insertions(+), 20 deletions(-) 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 3fdb4e6..77d58ed 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 @@ -36,7 +36,6 @@ public class ReservationRestController { public ResponseEntity> saveReservation( @Valid @RequestBody SaveReservationRequestDto request ) { - log.debug("[api][POST] /api/reservations"); return ResponseEntity .status(HttpStatus.CREATED) @@ -53,7 +52,6 @@ public ResponseEntity> saveReservation( public ResponseEntity>> getReservationList( @PageableDefault(size = 10, page = 0, sort = "id", direction = Sort.Direction.DESC) Pageable pageable ) { - log.debug("[api][GET] /api/reservations"); return ResponseEntity .status(HttpStatus.OK) @@ -70,7 +68,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 +84,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/facade/PreoccupyRoomsLockFacade.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/facade/PreoccupyRoomsLockFacade.java index e3cb3df..81892b3 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 bf13649..27615b0 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 c352c40..9c584d9 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 eda9709..afbeeb5 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,11 +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.exception.RoomNotFoundException; import com.fc.shimpyo_be.domain.room.repository.RoomRepository; import com.fc.shimpyo_be.global.util.DateTimeUtil; import lombok.RequiredArgsConstructor; @@ -50,7 +50,6 @@ public class ReservationService { public SaveReservationResponseDto saveReservation( Long memberId, SaveReservationRequestDto request, Map> reservationMap ) { - log.debug("{} ::: {}", getClass().getSimpleName(), "saveReservation"); // 회원 엔티티 조회 Member member = memberService.getMemberById(memberId); @@ -96,7 +95,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 +104,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 +152,6 @@ public ValidateReservationResultDto validate(Long memberId, List opsForValue = redisTemplate.opsForValue(); @@ -180,7 +176,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) { From 23218249be431b84168459f64059185ee217337f Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:11:59 +0900 Subject: [PATCH 09/15] =?UTF-8?q?refactor:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EB=82=B4=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EC=9D=91=EB=8B=B5=20=ED=83=80=EC=9E=85=20=EC=99=80?= =?UTF-8?q?=EC=9D=BC=EB=93=9C=EC=B9=B4=EB=93=9C=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=A0=95=ED=99=95=ED=95=9C=20Response=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=ED=83=80=EC=9E=85=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationRestController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 77d58ed..094d3c3 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; @@ -49,7 +50,7 @@ public ResponseEntity> saveReservation( } @GetMapping - public ResponseEntity>> getReservationList( + public ResponseEntity>> getReservationList( @PageableDefault(size = 10, page = 0, sort = "id", direction = Sort.Direction.DESC) Pageable pageable ) { From 6455cdef6a566ba66a6c46e8ce90e9960ad94786 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:14:08 +0900 Subject: [PATCH 10/15] =?UTF-8?q?refactor:=20=ED=8E=98=EC=9D=B4=EC=A7=95?= =?UTF-8?q?=20=EB=94=94=ED=8F=B4=ED=8A=B8=20=EC=9A=94=EC=B2=AD=EA=B0=92=20?= =?UTF-8?q?=EC=83=81=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationRestController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 094d3c3..150af73 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 @@ -32,6 +32,9 @@ public class ReservationRestController { private final PreoccupyRoomsLockFacade preoccupyRoomsLockFacade; private final ReservationLockFacade reservationLockFacade; private final SecurityUtil securityUtil; + private static final Integer PAGE_SIZE = 10; + private static final Integer PAGE_NUM = 0; + private static final String PAGE_SORT_BY = "id"; @PostMapping public ResponseEntity> saveReservation( @@ -51,7 +54,7 @@ public ResponseEntity> saveReservation( @GetMapping public ResponseEntity>> getReservationList( - @PageableDefault(size = 10, page = 0, sort = "id", direction = Sort.Direction.DESC) Pageable pageable + @PageableDefault(size = PAGE_SIZE, page = PAGE_NUM, sort = PAGE_SORT_BY, direction = Sort.Direction.DESC) Pageable pageable ) { return ResponseEntity From de66b63bb113a4be71b7c84071b8ff9758d6928a Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:17:24 +0900 Subject: [PATCH 11/15] =?UTF-8?q?refactor:=20ReservationService=EC=97=90?= =?UTF-8?q?=EC=84=9C=20RoomService.getRoomById(=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=8F=AC=ED=95=A8)=EB=A1=9C=20Room=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/reservation/service/ReservationService.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 afbeeb5..6e2c737 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 @@ -16,8 +16,7 @@ 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.exception.RoomNotFoundException; -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"; @@ -58,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) { From 9dd928b114df42d90f6584eefc566e403945ed99 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:30:35 +0900 Subject: [PATCH 12/15] =?UTF-8?q?test:=20ReservationServiceTest=20Product,?= =?UTF-8?q?=20Room=20Test=20Data=20=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EC=B6=9C=ED=95=B4=EC=84=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/service/ReservationServiceTest.java | 202 ++++++++++-------- 1 file changed, 107 insertions(+), 95 deletions(-) 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 f1045cc..30cb9ce 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; + } } From bb3f67f90eb60e382ec6ee740724e0f0bcfed40f Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 00:52:35 +0900 Subject: [PATCH 13/15] =?UTF-8?q?test:=20GetReservationListServiceTest=20P?= =?UTF-8?q?roduct,=20Room,=20ReservationProduct=20Test=20Data=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EC=B6=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetReservationListServiceTest.java | 202 ++++++++++-------- 1 file changed, 108 insertions(+), 94 deletions(-) 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 c94bd3e..b87db93 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; } } From 017c0838fa737455f9004a9ad90bf22a0174edd0 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 02:30:37 +0900 Subject: [PATCH 14/15] =?UTF-8?q?move:=20util=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=ED=95=98=EC=9C=84=EC=97=90=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=96=88=EB=8D=98=20constant=20=ED=8C=A8=ED=82=A4=EC=A7=80=20r?= =?UTF-8?q?eservation=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=ED=95=98=EC=9C=84=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{util => }/constant/ReservationValidationConstants.java | 2 +- .../reservation/dto/request/PreoccupyRoomItemRequestDto.java | 2 +- .../reservation/dto/request/PreoccupyRoomsRequestDto.java | 2 +- .../reservation/dto/request/ReleaseRoomItemRequestDto.java | 2 +- .../domain/reservation/dto/request/ReleaseRoomsRequestDto.java | 2 +- .../reservation/dto/request/SaveReservationRequestDto.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/com/fc/shimpyo_be/domain/reservation/{util => }/constant/ReservationValidationConstants.java (94%) diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/constant/ReservationValidationConstants.java similarity index 94% rename from src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java rename to src/main/java/com/fc/shimpyo_be/domain/reservation/constant/ReservationValidationConstants.java index 57e95df..5f93cf6 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/util/constant/ReservationValidationConstants.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/constant/ReservationValidationConstants.java @@ -1,4 +1,4 @@ -package com.fc.shimpyo_be.domain.reservation.util.constant; +package com.fc.shimpyo_be.domain.reservation.constant; import lombok.AccessLevel; import lombok.NoArgsConstructor; 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 51b5c77..9d6aa74 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,7 +4,7 @@ import jakarta.validation.constraints.Pattern; import lombok.Builder; -import static com.fc.shimpyo_be.domain.reservation.util.constant.ReservationValidationConstants.*; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; @Builder public record PreoccupyRoomItemRequestDto( 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 9a4bd66..3508084 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,7 +6,7 @@ import java.util.List; -import static com.fc.shimpyo_be.domain.reservation.util.constant.ReservationValidationConstants.*; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; @Builder public record PreoccupyRoomsRequestDto( 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 9276797..237cd05 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,7 +4,7 @@ import jakarta.validation.constraints.Pattern; import lombok.Builder; -import static com.fc.shimpyo_be.domain.reservation.util.constant.ReservationValidationConstants.*; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; @Builder public record ReleaseRoomItemRequestDto( 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 af63f0d..d421e82 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,7 +6,7 @@ import java.util.List; -import static com.fc.shimpyo_be.domain.reservation.util.constant.ReservationValidationConstants.*; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; @Builder public record ReleaseRoomsRequestDto( 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 bb6ee16..220cf3b 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,7 +10,7 @@ import java.util.List; -import static com.fc.shimpyo_be.domain.reservation.util.constant.ReservationValidationConstants.*; +import static com.fc.shimpyo_be.domain.reservation.constant.ReservationValidationConstants.*; @Builder public record SaveReservationRequestDto( From c9e45b8b7084c8703a578d7e8f2e76dbb9ff51e0 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Fri, 15 Dec 2023 13:32:22 +0900 Subject: [PATCH 15/15] =?UTF-8?q?fix:=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EC=83=81=EC=88=98=ED=99=94=20=ED=96=88?= =?UTF-8?q?=EB=8D=98=20=EA=B2=83=20Wrapper=20=ED=83=80=EC=9E=85=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=B4=20build=20=EC=97=90=EB=9F=AC=20-?= =?UTF-8?q?>=20=EC=9B=90=EC=8B=9C=20=ED=83=80=EC=9E=85=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/ReservationValidationConstants.java | 6 +++--- .../reservation/controller/ReservationRestController.java | 4 ++-- .../reservation/dto/request/ReleaseRoomItemRequestDto.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) 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 index 5f93cf6..98d0750 100644 --- 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 @@ -8,9 +8,9 @@ public class ReservationValidationConstants { // regex public static final String DATE_REGEX = "^\\d{4}-\\d{2}-\\d{2}$"; - public static final Integer RESERVATION_REQ_MIN_SIZE = 1; - public static final Integer RESERVATION_REQ_MAX_SIZE = 3; - public static final Integer TOTAL_PRICE_MIN_VALUE = 0; + 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 형식으로 입력하세요.)"; 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 150af73..fbce2b0 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 @@ -32,8 +32,8 @@ public class ReservationRestController { private final PreoccupyRoomsLockFacade preoccupyRoomsLockFacade; private final ReservationLockFacade reservationLockFacade; private final SecurityUtil securityUtil; - private static final Integer PAGE_SIZE = 10; - private static final Integer PAGE_NUM = 0; + private static final int PAGE_SIZE = 10; + private static final int PAGE_NUM = 0; private static final String PAGE_SORT_BY = "id"; @PostMapping 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 237cd05..46c2d3d 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 @@ -10,9 +10,9 @@ public record ReleaseRoomItemRequestDto( @NotNull Long roomId, - @Pattern(regexp = DATE_REGEX, message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = DATE_PATTERN_MESSAGE) String startDate, - @Pattern(regexp = DATE_REGEX, message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") + @Pattern(regexp = DATE_REGEX, message = DATE_PATTERN_MESSAGE) String endDate ) { }