From 7149d23a5c30f5afc00ba3c534d916f32d26b275 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 04:17:00 +0900 Subject: [PATCH 01/26] =?UTF-8?q?#127=20refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EC=8B=9C=EC=97=90=EB=8A=94=20redis=20key=20?= =?UTF-8?q?=EB=A7=8C=EB=A3=8C=20=EA=B8=B0=ED=95=9C=EC=9D=84=2035=EB=B6=84?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PreoccupyRoomsService.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 030b1f34..cb5cf482 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 @@ -1,8 +1,8 @@ package com.fc.shimpyo_be.domain.reservation.service; import com.fc.shimpyo_be.domain.reservation.dto.CheckAvailableRoomsResultDto; -import com.fc.shimpyo_be.domain.reservation.dto.request.PreoccupyRoomsRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.request.PreoccupyRoomItemRequestDto; +import com.fc.shimpyo_be.domain.reservation.dto.request.PreoccupyRoomsRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.response.ValidatePreoccupyRoomResponseDto; import com.fc.shimpyo_be.domain.room.service.RoomService; import com.fc.shimpyo_be.global.util.DateTimeUtil; @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.ZoneId; import java.util.*; @@ -23,7 +24,7 @@ public class PreoccupyRoomsService { private final RoomService roomService; private final RedisTemplate redisTemplate; - private static final String REDIS_KEY_FORMAT = "roomId:%d:%s"; + private static final String PREOCCUPY_REDIS_KEY_FORMAT = "roomId:%d:%s"; private static final String CHECK_DUPLICATE_FORMAT = "%d:%s:%s"; public CheckAvailableRoomsResultDto checkAvailable(Long memberId, PreoccupyRoomsRequestDto request) { @@ -55,7 +56,7 @@ public CheckAvailableRoomsResultDto checkAvailable(Long memberId, PreoccupyRooms LocalDate targetDate = startDate; while(targetDate.isBefore(endDate)) { - String key = String.format(REDIS_KEY_FORMAT, roomId, targetDate); + String key = String.format(PREOCCUPY_REDIS_KEY_FORMAT, roomId, targetDate); Object value = opsForValue.get(key); log.info("roomId: {}, targetDate: {}, value: {}", roomId, targetDate, value); @@ -120,17 +121,17 @@ public void preoccupy(CheckAvailableRoomsResultDto resultDto) { Map map = preoccupyMap.get(roomResult.roomId()); opsForValue.multiSet(map); - Date expireDate = convertLocalDateToDate(DateTimeUtil.toLocalDate(roomResult.endDate())); + Date expireDate = convertLocalDateTimeToDate(LocalDateTime.now().plusMinutes(35)); for (String key : map.keySet()) { redisTemplate.expireAt(key, expireDate); } } } - private Date convertLocalDateToDate(LocalDate localDate) { + private Date convertLocalDateTimeToDate(LocalDateTime dateTime) { return Date.from( - localDate - .atStartOfDay(ZoneId.systemDefault()) + dateTime + .atZone(ZoneId.systemDefault()) .toInstant() ); } From 376099e7cfcd7cf84b178ccbfb94b5ce9889a5b4 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 04:19:28 +0900 Subject: [PATCH 02/26] =?UTF-8?q?#127=20feat:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=A0=84=20=EA=B2=80=EC=A6=9D=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=A5=BC=20=EB=8B=B4=EB=8A=94=20Result=20DTO=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ValidateReservationResultDto.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/fc/shimpyo_be/domain/reservation/dto/ValidateReservationResultDto.java diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/ValidateReservationResultDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/ValidateReservationResultDto.java new file mode 100644 index 00000000..87e3ebf2 --- /dev/null +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/ValidateReservationResultDto.java @@ -0,0 +1,14 @@ +package com.fc.shimpyo_be.domain.reservation.dto; + +import lombok.Builder; + +import java.util.List; +import java.util.Map; + +@Builder +public record ValidateReservationResultDto( + boolean isAvailable, + List unavailableIds, + Map> confirmMap +) { +} From 3b14cea30deb136d4990274a2a311336ba228a00 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 04:25:37 +0900 Subject: [PATCH 03/26] =?UTF-8?q?#127=20refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A0=84=20=EC=84=A0=EC=A0=90=ED=95=9C=20=EA=B0=9D=EC=8B=A4?= =?UTF-8?q?=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20&=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=EC=8B=9C=20=EC=84=A0=EC=A0=90=EB=90=9C=20?= =?UTF-8?q?=EA=B0=9D=EC=8B=A4=EC=9D=98=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?=ED=82=A4=EA=B0=92=20=EB=A7=8C=EB=A3=8C=EA=B8=B0=ED=95=9C=20?= =?UTF-8?q?=EC=9E=AC=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 68 +++++++++++++------ 1 file changed, 47 insertions(+), 21 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 5fe03cc5..a1bfb1cf 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 @@ -1,17 +1,15 @@ package com.fc.shimpyo_be.domain.reservation.service; import com.fc.shimpyo_be.domain.member.entity.Member; -import com.fc.shimpyo_be.domain.member.exception.MemberNotFoundException; -import com.fc.shimpyo_be.domain.member.repository.MemberRepository; +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; 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.ValidateReservationResultResponseDto; import com.fc.shimpyo_be.domain.reservation.entity.Reservation; -import com.fc.shimpyo_be.domain.reservation.exception.InvalidRequestException; import com.fc.shimpyo_be.domain.reservation.repository.ReservationRepository; import com.fc.shimpyo_be.domain.reservation.util.ReservationMapper; import com.fc.shimpyo_be.domain.reservationproduct.dto.request.ReservationProductRequestDto; @@ -19,7 +17,6 @@ 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.global.exception.ErrorCode; import com.fc.shimpyo_be.global.util.DateTimeUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -32,10 +29,8 @@ import org.springframework.util.ObjectUtils; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; +import java.time.ZoneId; +import java.util.*; @Slf4j @RequiredArgsConstructor @@ -44,22 +39,24 @@ public class ReservationService { private final ReservationRepository reservationRepository; private final ReservationProductRepository reservationProductRepository; - private final MemberRepository memberRepository; + private final MemberService memberService; private final RoomRepository roomRepository; private final RedisTemplate redisTemplate; private static final String REDIS_ROOM_KEY_FORMAT = "roomId:%d:%s"; @Transactional - public SaveReservationResponseDto saveReservation(Long memberId, SaveReservationRequestDto request) { + public SaveReservationResponseDto saveReservation( + Long memberId, SaveReservationRequestDto request, Map> reservationMap + ) { log.debug("{} ::: {}", getClass().getSimpleName(), "saveReservation"); // 회원 엔티티 조회 - Member member = memberRepository.findById(memberId) - .orElseThrow(MemberNotFoundException::new); + Member member = memberService.getMemberById(memberId); // 객실 엔티티 조회 후, 예약 숙소 리스트 생성 List reservationProducts = new ArrayList<>(); for (ReservationProductRequestDto reservationProductDto : request.reservationProducts()) { + Room room = roomRepository.findById(reservationProductDto.roomId()) .orElseThrow(RoomNotFoundException::new); @@ -73,6 +70,8 @@ public SaveReservationResponseDto saveReservation(Long memberId, SaveReservation .price(reservationProductDto.price()) .build() ); + + confirmReservationProduct(reservationMap.get(room.getId()), reservationProductDto.endDate()); } // 예약 저장 @@ -99,42 +98,52 @@ public Page getReservationInfoList(Long memberId, Pa .map(ReservationMapper::from); } - public ValidateReservationResultResponseDto validate(Long memberId, List reservationProducts) { + public ValidateReservationResultDto validate(Long memberId, List reservationProducts) { log.debug("{} ::: {}", getClass().getSimpleName(), "validate"); ValueOperations opsForValue = redisTemplate.opsForValue(); boolean isValid = true; List invalidRoomIds = new ArrayList<>(); + Map> confirmMap = new HashMap<>(); + String memberIdValue = String.valueOf(memberId); + for (ReservationProductRequestDto reservationProduct : reservationProducts) { + LocalDate targetDate = DateTimeUtil.toLocalDate(reservationProduct.startDate()); LocalDate endDate = DateTimeUtil.toLocalDate(reservationProduct.endDate()); - + Long roomId = reservationProduct.roomId(); List keys = new LinkedList<>(); + while (targetDate.isBefore(endDate)) { - keys.add(String.format(REDIS_ROOM_KEY_FORMAT, reservationProduct.roomId(), targetDate)); + keys.add(String.format(REDIS_ROOM_KEY_FORMAT, roomId, targetDate)); + targetDate = targetDate.plusDays(1); } + confirmMap.put(roomId, keys); + List values = opsForValue.multiGet(keys); - String memberIdValue = String.valueOf(memberId); if (ObjectUtils.isEmpty(values)) { - throw new InvalidRequestException(ErrorCode.INVALID_RESERVATION_REQUEST); + isValid = false; + invalidRoomIds.add(roomId); + continue; } for (Object value : values) { - if (!memberIdValue.equals(value)) { + if (Objects.isNull(value) || !memberIdValue.equals(value)) { isValid = false; - invalidRoomIds.add(Long.valueOf((String) value)); + invalidRoomIds.add(roomId); break; } } } - return ValidateReservationResultResponseDto.builder() + return ValidateReservationResultDto.builder() .isAvailable(isValid) .unavailableIds(invalidRoomIds) + .confirmMap(confirmMap) .build(); } @@ -162,4 +171,21 @@ public void releaseRooms(Long memberId, ReleaseRoomsRequestDto request) { redisTemplate.delete(deleteKeys); } } + + private void confirmReservationProduct(List reservationKeys, String endDate) { + log.debug("{} ::: {}", getClass().getSimpleName(), "confirmReservationProduct"); + + Date expireDate = convertLocalDateToDate(DateTimeUtil.toLocalDate(endDate)); + for (String key : reservationKeys) { + redisTemplate.expireAt(key, expireDate); + } + } + + private Date convertLocalDateToDate(LocalDate localDate) { + return Date.from( + localDate + .atStartOfDay(ZoneId.systemDefault()) + .toInstant() + ); + } } From 308018e09328ba30e51d41305c94d549635e707b Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 04:26:31 +0900 Subject: [PATCH 04/26] =?UTF-8?q?#127=20refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A0=84=20=EC=98=88=EC=95=BD=20=EC=A0=80=EC=9E=A5=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=20=EC=97=AC=EB=B6=80=20=EA=B2=80=EC=A6=9D=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=97=90=20=EB=8C=80=ED=95=9C=20Custom=20Exception=20?= =?UTF-8?q?&=20ErrorCode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ReserveNotAvailableException.java | 8 ++++---- .../com/fc/shimpyo_be/global/exception/ErrorCode.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/ReserveNotAvailableException.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/ReserveNotAvailableException.java index b19e27a6..44af0c37 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/ReserveNotAvailableException.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/exception/ReserveNotAvailableException.java @@ -11,13 +11,13 @@ public class ReserveNotAvailableException extends RuntimeException { private ValidateReservationResultResponseDto data; public ReserveNotAvailableException() { - super(ErrorCode.UNAVAILABLE_ROOMS.getSimpleMessage()); - this.errorCode = ErrorCode.UNAVAILABLE_ROOMS; + super(ErrorCode.RESERVATION_VALIDATION_FAIL.getSimpleMessage()); + this.errorCode = ErrorCode.RESERVATION_VALIDATION_FAIL; } public ReserveNotAvailableException(ValidateReservationResultResponseDto data) { - super(ErrorCode.UNAVAILABLE_ROOMS.getSimpleMessage()); - this.errorCode = ErrorCode.UNAVAILABLE_ROOMS; + super(ErrorCode.RESERVATION_VALIDATION_FAIL.getSimpleMessage()); + this.errorCode = ErrorCode.RESERVATION_VALIDATION_FAIL; this.data = data; } } diff --git a/src/main/java/com/fc/shimpyo_be/global/exception/ErrorCode.java b/src/main/java/com/fc/shimpyo_be/global/exception/ErrorCode.java index 385c8acb..ca992834 100644 --- a/src/main/java/com/fc/shimpyo_be/global/exception/ErrorCode.java +++ b/src/main/java/com/fc/shimpyo_be/global/exception/ErrorCode.java @@ -25,7 +25,7 @@ public enum ErrorCode { // 예약 UNAVAILABLE_ROOMS(HttpStatus.BAD_REQUEST, "예약 불가능한 방이 존재합니다."), LOCK_FAIL(HttpStatus.BAD_REQUEST, "요청 완료에 실패했습니다. 재시도가 필요합니다."), - INVALID_RESERVATION_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 예약 요청 데이터입니다."), + RESERVATION_VALIDATION_FAIL(HttpStatus.BAD_REQUEST, "예약 선점 기한이 만료되었거나, 잘못된 예약 요청으로 예약이 불가합니다."), // 예약 숙소 RESERVATION_PRODUCT_NOT_FOUND(HttpStatus.BAD_REQUEST, "예약 숙소 정보를 찾을 수 없습니다."), From 9162d54e94bd4cc6038714303dbdcefaba863526 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 04:28:47 +0900 Subject: [PATCH 05/26] =?UTF-8?q?#127=20refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A0=84=20=EA=B2=80=EC=A6=9D=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EA=B3=BC=20=EC=98=88=EC=95=BD=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=ED=8C=8C=EB=9D=BC=EB=A9=94?= =?UTF-8?q?=ED=84=B0=EA=B0=80=20=EC=B6=94=EA=B0=80=EB=90=A8=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EB=B3=80=EA=B2=BD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/reservation/facade/ReservationLockFacade.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 a0ef500e..bf136498 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 @@ -1,5 +1,6 @@ package com.fc.shimpyo_be.domain.reservation.facade; +import com.fc.shimpyo_be.domain.reservation.dto.ValidateReservationResultDto; import com.fc.shimpyo_be.domain.reservation.dto.request.SaveReservationRequestDto; import com.fc.shimpyo_be.domain.reservation.dto.response.SaveReservationResponseDto; import com.fc.shimpyo_be.domain.reservation.dto.response.ValidateReservationResultResponseDto; @@ -34,7 +35,7 @@ public SaveReservationResponseDto saveReservation(Long memberId, SaveReservation throw new RedissonLockFailException(); } - ValidateReservationResultResponseDto resultDto = reservationService.validate(memberId, request.reservationProducts()); + ValidateReservationResultDto resultDto = reservationService.validate(memberId, request.reservationProducts()); if(!resultDto.isAvailable()) { log.debug("[{}][validate rooms result] isAvailable = {}, unavailableIds = {}", currentWorker, false, resultDto.unavailableIds()); @@ -46,9 +47,10 @@ public SaveReservationResponseDto saveReservation(Long memberId, SaveReservation .build() ); } + log.debug("[{}][validate rooms result] isAvailable = {}, unavailableIds = {}", currentWorker, true, resultDto.unavailableIds()); - return reservationService.saveReservation(memberId, request); + return reservationService.saveReservation(memberId, request, resultDto.confirmMap()); } catch (InterruptedException exception) { log.error("exception : {}, message : {}", exception.getClass().getSimpleName(), exception.getMessage()); From 804ed25030358780a63df7da69e74f40a1fea694 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 04:29:29 +0900 Subject: [PATCH 06/26] =?UTF-8?q?#127=20test:=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20Test=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/ReservationLockFacadeTest.java | 147 +++++++++++++++++- .../unit/service/ReservationServiceTest.java | 50 +++++- .../star/unit/service/StarServiceTest.java | 2 +- 3 files changed, 188 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java index dd45f9a4..2adc8015 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java @@ -1,27 +1,39 @@ package com.fc.shimpyo_be.domain.reservation.unit.facade; import com.fc.shimpyo_be.config.AbstractContainersSupport; +import com.fc.shimpyo_be.config.DatabaseCleanUp; +import com.fc.shimpyo_be.config.TestDBCleanerConfig; +import com.fc.shimpyo_be.domain.member.entity.Authority; +import com.fc.shimpyo_be.domain.member.entity.Member; +import com.fc.shimpyo_be.domain.member.repository.MemberRepository; +import com.fc.shimpyo_be.domain.product.entity.*; +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.entity.PayMethod; import com.fc.shimpyo_be.domain.reservation.facade.ReservationLockFacade; import com.fc.shimpyo_be.domain.reservationproduct.dto.request.ReservationProductRequestDto; +import com.fc.shimpyo_be.domain.room.entity.Room; +import com.fc.shimpyo_be.domain.room.entity.RoomOption; +import com.fc.shimpyo_be.domain.room.entity.RoomPrice; +import com.fc.shimpyo_be.domain.room.repository.RoomRepository; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.util.StopWatch; import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; @Slf4j +@Import(TestDBCleanerConfig.class) @SpringBootTest class ReservationLockFacadeTest extends AbstractContainersSupport { @@ -31,6 +43,22 @@ class ReservationLockFacadeTest extends AbstractContainersSupport { @Autowired private RedisTemplate redisTemplate; + @Autowired + private DatabaseCleanUp databaseCleanUp; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private ProductRepository productRepository; + + @Autowired + private RoomRepository roomRepository; + + private final String[] tableNameArray = { + "member", "product", "room", "product_option", "address", "room_option", "amenity" + }; + private static final ThreadLocal threadLocalStopWatch = ThreadLocal.withInitial(StopWatch::new); @BeforeEach @@ -41,6 +69,115 @@ void setUp() { long memberId4 = 4L; long memberId5 = 5L; + databaseCleanUp.cleanUp(tableNameArray); + + for (int i = 1; i <= 5; i++) { + String name = "member" + i; + memberRepository.save( + Member.builder() + .email(name + "@email.com") + .name(name) + .password("password") + .photoUrl("member photo url") + .authority(Authority.ROLE_USER) + .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 <= 5; i++) { + String roomName = "객실" + i; + rooms.add( + roomRepository.save( + Room.builder() + .product(products.get((i - 1) % 3)) + .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() + ) + ); + } + saveRedisData(memberId1, 2L, LocalDate.of(2023, 11, 20), LocalDate.of(2023, 11, 23)); saveRedisData(memberId1, 3L, LocalDate.of(2023, 11, 24), LocalDate.of(2023, 11, 26)); @@ -196,7 +333,7 @@ private void saveRedisData(long memberId, long roomId, LocalDate start, LocalDat while (start.isBefore(end)) { String key = String.format(keyFormat, roomId, start); - valueOperations.set(key, String.valueOf(memberId), 50, TimeUnit.SECONDS); + valueOperations.set(key, String.valueOf(memberId), 60, TimeUnit.SECONDS); start = start.plusDays(1); } } 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 0cd4d610..881b0fcc 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 @@ -19,6 +19,7 @@ import com.fc.shimpyo_be.domain.room.entity.RoomOption; import com.fc.shimpyo_be.domain.room.entity.RoomPrice; import com.fc.shimpyo_be.domain.room.repository.RoomRepository; +import com.fc.shimpyo_be.global.util.DateTimeUtil; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -27,13 +28,15 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ThreadLocalRandom; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; @Slf4j @Import(TestDBCleanerConfig.class) @@ -191,8 +194,16 @@ void saveReservation_test() { ), PayMethod.CREDIT_CARD, 350000 ); + Map> map = new HashMap<>(); + for (ReservationProductRequestDto reservationProduct : requestDto.reservationProducts()) { + map.put( + reservationProduct.roomId(), + getKeyList(reservationProduct.roomId(), reservationProduct.startDate(), reservationProduct.endDate()) + ); + } + //when - SaveReservationResponseDto result = reservationService.saveReservation(memberId, requestDto); + SaveReservationResponseDto result = reservationService.saveReservation(memberId, requestDto, map); //then assertThat(result.reservationId()).isNotNull(); @@ -219,8 +230,16 @@ void saveReservation_memberNotFound_test() { ), PayMethod.CREDIT_CARD, 350000 ); + Map> map = new HashMap<>(); + for (ReservationProductRequestDto reservationProduct : requestDto.reservationProducts()) { + map.put( + reservationProduct.roomId(), + getKeyList(reservationProduct.roomId(), reservationProduct.startDate(), reservationProduct.endDate()) + ); + } + //when & then - assertThatThrownBy(() -> reservationService.saveReservation(memberId, requestDto)) + assertThatThrownBy(() -> reservationService.saveReservation(memberId, requestDto, map)) .isInstanceOf(MemberNotFoundException.class); } @@ -244,8 +263,29 @@ void saveReservation_roomNotFound_test() { ), PayMethod.CREDIT_CARD, 350000 ); + Map> map = new HashMap<>(); + for (ReservationProductRequestDto reservationProduct : requestDto.reservationProducts()) { + map.put( + reservationProduct.roomId(), + getKeyList(reservationProduct.roomId(), reservationProduct.startDate(), reservationProduct.endDate()) + ); + } + //when & then - assertThatThrownBy(() -> reservationService.saveReservation(memberId, requestDto)) + assertThatThrownBy(() -> reservationService.saveReservation(memberId, requestDto, map)) .isInstanceOf(RoomNotFoundException.class); } + + private List getKeyList(Long roomId, String startDate, String endDate) { + List keyList = new ArrayList<>(); + + LocalDate targetDate = DateTimeUtil.toLocalDate(startDate); + LocalDate maxDate = DateTimeUtil.toLocalDate(endDate); + while (targetDate.isBefore(maxDate)) { + keyList.add("roomId:" + roomId + ":" + targetDate); + targetDate = targetDate.plusDays(1); + } + + return keyList; + } } diff --git a/src/test/java/com/fc/shimpyo_be/domain/star/unit/service/StarServiceTest.java b/src/test/java/com/fc/shimpyo_be/domain/star/unit/service/StarServiceTest.java index fa2a1939..f49f9aba 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/star/unit/service/StarServiceTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/star/unit/service/StarServiceTest.java @@ -118,7 +118,7 @@ void setUp() { .checkOut(LocalTime.of(12, 0)) .build() ) - .endDate(LocalDate.of(2023, 11, 29)) + .endDate(LocalDate.now().minusDays(7)) .build(); reservationProductBeforeCheckOut = ReservationProduct.builder() From c606eb5a7eb0a335ba6aa5217dde4601a55d317a Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:07:26 +0900 Subject: [PATCH 07/26] =?UTF-8?q?#127=20refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20Request/Response=20=EC=99=80=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=EA=B2=B0=EC=A0=9C=20Request=20DTO=EC=97=90=20?= =?UTF-8?q?=EC=9E=A5=EB=B0=94=EA=B5=AC=EB=8B=88=20=EC=8B=9D=EB=B3=84?= =?UTF-8?q?=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/request/PreoccupyRoomItemRequestDto.java | 2 ++ .../dto/response/ValidatePreoccupyRoomResponseDto.java | 1 + .../dto/request/ReservationProductRequestDto.java | 2 ++ 3 files changed, 5 insertions(+) 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 59a39697..09b90452 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 @@ -6,6 +6,8 @@ @Builder public record PreoccupyRoomItemRequestDto( + @NotNull + Long cartId, @NotNull Long roomCode, @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") diff --git a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/response/ValidatePreoccupyRoomResponseDto.java b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/response/ValidatePreoccupyRoomResponseDto.java index 836c4dfd..92cef81c 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/response/ValidatePreoccupyRoomResponseDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/reservation/dto/response/ValidatePreoccupyRoomResponseDto.java @@ -4,6 +4,7 @@ @Builder public record ValidatePreoccupyRoomResponseDto( + Long cartId, Long roomCode, String startDate, String endDate, 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 f98c4e65..a57bb0fb 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 @@ -7,6 +7,8 @@ @Builder public record ReservationProductRequestDto( + @NotNull + Long cartId, @NotNull Long roomId, @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "올바른 날짜 형식이 아닙니다.(yyyy-MM-dd 형식으로 입력하세요.)") From 08df65d51dad5d9f6ccec51d8c9129e0dfcea8b4 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:08:26 +0900 Subject: [PATCH 08/26] =?UTF-8?q?#127=20rename:=20ReservationMapper=20stat?= =?UTF-8?q?ic=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EB=AA=A8=EB=91=90?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shimpyo_be/domain/reservation/util/ReservationMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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/ReservationMapper.java index df48a80f..0c5d3daa 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/ReservationMapper.java @@ -14,7 +14,7 @@ public class ReservationMapper { - public static ReservationInfoResponseDto from(ReservationProduct reservationProduct) { + public static ReservationInfoResponseDto toReservationInfoResponseDto(ReservationProduct reservationProduct) { Reservation reservation = reservationProduct.getReservation(); Room room = reservationProduct.getRoom(); Product product = room.getProduct(); @@ -39,7 +39,7 @@ public static ReservationInfoResponseDto from(ReservationProduct reservationProd .build(); } - public static SaveReservationResponseDto from(Reservation reservation) { + public static SaveReservationResponseDto toSaveReservationResponseDto(Reservation reservation) { List reservationProductDtos = new ArrayList<>(); for (ReservationProduct reservationProduct : reservation.getReservationProducts()) { From fb01a3d8e629d93f88a1cc4aaac6f7e231dee885 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:09:42 +0900 Subject: [PATCH 09/26] =?UTF-8?q?#127=20refactor:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EC=8B=9C=20=EC=9D=91=EB=8B=B5=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EC=97=90=20=EC=9A=94=EC=B2=AD=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20=EC=9E=A5=EB=B0=94=EA=B5=AC=EB=8B=88=20?= =?UTF-8?q?=EC=8B=9D=EB=B3=84=EC=9E=90=20cartId=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=B4=EC=84=9C=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/reservation/service/PreoccupyRoomsService.java | 3 +++ 1 file changed, 3 insertions(+) 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 cb5cf482..c352c409 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 @@ -41,6 +41,7 @@ public CheckAvailableRoomsResultDto checkAvailable(Long memberId, PreoccupyRooms LocalDate startDate = DateTimeUtil.toLocalDate(room.startDate()); LocalDate endDate = DateTimeUtil.toLocalDate(room.endDate()); + Long cartId = room.cartId(); Long roomCode = room.roomCode(); List roomIds = roomService.getRoomIdsByCode(roomCode); @@ -78,6 +79,7 @@ public CheckAvailableRoomsResultDto checkAvailable(Long memberId, PreoccupyRooms roomResults.add( ValidatePreoccupyRoomResponseDto.builder() + .cartId(cartId) .roomCode(roomCode) .startDate(DateTimeUtil.toString(startDate)) .endDate(DateTimeUtil.toString(endDate)) @@ -96,6 +98,7 @@ public CheckAvailableRoomsResultDto checkAvailable(Long memberId, PreoccupyRooms roomResults.add( ValidatePreoccupyRoomResponseDto.builder() + .cartId(cartId) .roomCode(roomCode) .startDate(DateTimeUtil.toString(startDate)) .endDate(DateTimeUtil.toString(endDate)) From 55cdbe0073cf1ae42de0aab4866ef8953d7b1ae1 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:11:52 +0900 Subject: [PATCH 10/26] =?UTF-8?q?#127=20feat:=20=EC=9E=A5=EB=B0=94?= =?UTF-8?q?=EA=B5=AC=EB=8B=88=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20deleteCart=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=98=A4=EB=B2=84=EB=A1=9C=EB=94=A9=20(memberId,=20cartId)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shimpyo_be/domain/cart/service/CartService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/fc/shimpyo_be/domain/cart/service/CartService.java b/src/main/java/com/fc/shimpyo_be/domain/cart/service/CartService.java index 84839b92..95c5aacc 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/cart/service/CartService.java +++ b/src/main/java/com/fc/shimpyo_be/domain/cart/service/CartService.java @@ -81,6 +81,18 @@ public CartDeleteResponse deleteCart(final Long cartId) { return CartMapper.toCartDeleteResponse(cart); } + @Transactional + public CartDeleteResponse deleteCart(final Long memberId, final Long cartId) { + Cart cart = cartRepository.findById(cartId).orElseThrow(CartNotFoundException::new); + + if (!cart.getMember().getId().equals(memberId)) { + throw new CartNotDeleteException(); + } + cartRepository.deleteById(cart.getId()); + + return CartMapper.toCartDeleteResponse(cart); + } + private CartResponse getCartResponse(final Cart cart) { List rooms = Optional.of(roomRepository.findByCode(cart.getRoomCode())) .orElseThrow(); From 0244889007a6b5c45841d592e634580ba2c4591b Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:14:23 +0900 Subject: [PATCH 11/26] =?UTF-8?q?#127=20feat:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=8B=9C=20=EC=98=88=EC=95=BD=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EB=90=9C=20=EC=9E=A5=EB=B0=94=EA=B5=AC=EB=8B=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 a1bfb1cf..eda97096 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 @@ -1,5 +1,6 @@ package com.fc.shimpyo_be.domain.reservation.service; +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; @@ -41,6 +42,7 @@ public class ReservationService { private final ReservationProductRepository reservationProductRepository; private final MemberService memberService; private final RoomRepository roomRepository; + private final CartService cartService; private final RedisTemplate redisTemplate; private static final String REDIS_ROOM_KEY_FORMAT = "roomId:%d:%s"; @@ -60,6 +62,11 @@ public SaveReservationResponseDto saveReservation( Room room = roomRepository.findById(reservationProductDto.roomId()) .orElseThrow(RoomNotFoundException::new); + // 장바구니 아이템 삭제 + if (reservationProductDto.cartId() > 0) { + cartService.deleteCart(member.getId(), reservationProductDto.cartId()); + } + reservationProducts.add( ReservationProduct.builder() .room(room) @@ -84,7 +91,7 @@ public SaveReservationResponseDto saveReservation( .build() ); - return ReservationMapper.from(reservation); + return ReservationMapper.toSaveReservationResponseDto(reservation); } @Transactional(readOnly = true) @@ -95,7 +102,7 @@ public Page getReservationInfoList(Long memberId, Pa return reservationProductRepository .findAllInReservationIds(reservationIds, pageable) - .map(ReservationMapper::from); + .map(ReservationMapper::toReservationInfoResponseDto); } public ValidateReservationResultDto validate(Long memberId, List reservationProducts) { From 1c3d77c75d65189fdc4cc2562609af3b024d4482 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:16:08 +0900 Subject: [PATCH 12/26] =?UTF-8?q?#127=20test:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B3=BC=20=EC=98=88=EC=95=BD=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=9D=98=20Request/Response=20DTO=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Unit=20Test=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationRestControllerTest.java | 20 +++-- .../facade/ReservationLockFacadeTest.java | 22 ++--- .../unit/service/ReservationServiceTest.java | 88 +++++++++++++++++-- 3 files changed, 103 insertions(+), 27 deletions(-) diff --git a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/controller/ReservationRestControllerTest.java b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/controller/ReservationRestControllerTest.java index 47ffbe66..7fd17cf2 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/controller/ReservationRestControllerTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/controller/ReservationRestControllerTest.java @@ -83,6 +83,7 @@ void saveReservation_Api_test() throws Exception { .reservationProducts( List.of( ReservationProductRequestDto.builder() + .cartId(1L) .roomId(1L) .startDate("2023-11-20") .endDate("2023-11-23") @@ -91,6 +92,7 @@ void saveReservation_Api_test() throws Exception { .price(300000) .build(), ReservationProductRequestDto.builder() + .cartId(2L) .roomId(3L) .startDate("2023-12-10") .endDate("2023-12-12") @@ -218,11 +220,13 @@ void checkAvailableAndPreoccupy_test() throws Exception { .rooms( List.of( PreoccupyRoomItemRequestDto.builder() + .cartId(1L) .roomCode(1001L) .startDate("2023-12-23") .endDate("2023-12-25") .build(), PreoccupyRoomItemRequestDto.builder() + .cartId(2L) .roomCode(1003L) .startDate("2023-11-11") .endDate("2023-11-14") @@ -237,12 +241,14 @@ void checkAvailableAndPreoccupy_test() throws Exception { .roomResults( List.of( ValidatePreoccupyRoomResponseDto.builder() + .cartId(1L) .roomCode(1001L) .startDate("2023-12-23") .endDate("2023-12-25") .roomId(1L) .build(), ValidatePreoccupyRoomResponseDto.builder() + .cartId(2L) .roomCode(1003L) .startDate("2023-11-11") .endDate("2023-11-14") @@ -279,16 +285,16 @@ void checkAvailableAndPreoccupy_size_validation_error_test() throws Exception { .rooms( List.of( PreoccupyRoomItemRequestDto.builder() - .startDate("2023-12-23").endDate("2023-12-25") + .cartId(1L).roomCode(1001L).startDate("2023-12-23").endDate("2023-12-25") .build(), PreoccupyRoomItemRequestDto.builder() - .roomCode(1002L).startDate("2023-11-11").endDate("2023-11-14") + .cartId(2L).roomCode(1002L).startDate("2023-11-11").endDate("2023-11-14") .build(), PreoccupyRoomItemRequestDto.builder() - .roomCode(1003L).startDate("2023-11-11").endDate("2023-11-14") + .cartId(3L).roomCode(1003L).startDate("2023-11-11").endDate("2023-11-14") .build(), PreoccupyRoomItemRequestDto.builder() - .roomCode(1004L).startDate("2023-11-16").endDate("2023-11-18") + .cartId(4L).roomCode(1004L).startDate("2023-11-16").endDate("2023-11-18") .build() ) ) @@ -319,13 +325,13 @@ void checkAvailableAndPreoccupy_localdate_validation_error_test() throws Excepti .rooms( List.of( PreoccupyRoomItemRequestDto.builder() - .roomCode(1001L).startDate("202-12-23").endDate("2023-12-25") + .cartId(1L).roomCode(1001L).startDate("202-12-23").endDate("2023-12-25") .build(), PreoccupyRoomItemRequestDto.builder() - .roomCode(1002L).startDate("2023-11-11").endDate("2023-11-14") + .cartId(2L).roomCode(1002L).startDate("2023-11-11").endDate("2023-11-14") .build(), PreoccupyRoomItemRequestDto.builder() - .roomCode(1003L).startDate("2023-11-11").endDate("2023-11-14") + .cartId(3L).roomCode(1003L).startDate("2023-11-11").endDate("2023-11-14") .build() ) ) diff --git a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java index 2adc8015..5aaea371 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/reservation/unit/facade/ReservationLockFacadeTest.java @@ -205,46 +205,46 @@ void saveReservation_test() throws InterruptedException { SaveReservationRequestDto request1 = new SaveReservationRequestDto( List.of( - new ReservationProductRequestDto(2L, "2023-11-20", "2023-11-23", + new ReservationProductRequestDto(1L, 2L, "2023-11-20", "2023-11-23", "visitor1", "010-1111-1111", 100000), - new ReservationProductRequestDto(3L, "2023-11-24", "2023-11-26", + new ReservationProductRequestDto(2L, 3L, "2023-11-24", "2023-11-26", "visitor2", "010-2222-2222", 150000) ), PayMethod.KAKAO_PAY, 250000 ); SaveReservationRequestDto request2 = new SaveReservationRequestDto( - List.of(new ReservationProductRequestDto(4L, "2023-10-10", "2023-10-14", + List.of(new ReservationProductRequestDto(3L, 4L, "2023-10-10", "2023-10-14", "visitor3", "010-3333-3333", 125000)), PayMethod.CREDIT_CARD, 125000 ); SaveReservationRequestDto request3 = new SaveReservationRequestDto( List.of( - new ReservationProductRequestDto(2L, "2023-11-10", "2023-11-14", + new ReservationProductRequestDto(4L, 2L, "2023-11-10", "2023-11-14", "visitor", "010-1111-1111", 90000), - new ReservationProductRequestDto(5L, "2023-10-17", "2023-10-20", + new ReservationProductRequestDto(5L, 5L, "2023-10-17", "2023-10-20", "visitor", "010-1111-1111", 110000), - new ReservationProductRequestDto(3L, "2023-10-10", "2023-10-14", + new ReservationProductRequestDto(6L, 3L, "2023-10-10", "2023-10-14", "visitor", "010-1111-1111", 100000) ), PayMethod.NAVER_PAY, 300000 ); SaveReservationRequestDto request4 = new SaveReservationRequestDto( List.of( - new ReservationProductRequestDto(4L, "2023-10-05", "2023-10-07", + new ReservationProductRequestDto(7L, 4L, "2023-10-05", "2023-10-07", "visitor", "010-1111-1111", 125000), - new ReservationProductRequestDto(5L, "2023-10-10", "2023-10-14", + new ReservationProductRequestDto(8L, 5L, "2023-10-10", "2023-10-14", "visitor", "010-1111-1111", 125000) ), PayMethod.KAKAO_PAY, 250000 ); SaveReservationRequestDto request5 = new SaveReservationRequestDto( List.of( - new ReservationProductRequestDto(1L, "2023-10-10", "2023-10-14", + new ReservationProductRequestDto(9L, 1L, "2023-10-10", "2023-10-14", "visitor4", "010-4444-4444", 150000), - new ReservationProductRequestDto(2L, "2023-12-11", "2023-12-15", + new ReservationProductRequestDto(10L, 2L, "2023-12-11", "2023-12-15", "visitor4", "010-4444-4444", 150000), - new ReservationProductRequestDto(4L, "2023-11-11", "2023-11-14", + new ReservationProductRequestDto(11L, 4L, "2023-11-11", "2023-11-14", "visitor4", "010-4444-4444", 100000) ), PayMethod.PAYPAL, 400000 ); 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 881b0fcc..f1045ccb 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 @@ -3,6 +3,8 @@ import com.fc.shimpyo_be.config.AbstractContainersSupport; import com.fc.shimpyo_be.config.DatabaseCleanUp; import com.fc.shimpyo_be.config.TestDBCleanerConfig; +import com.fc.shimpyo_be.domain.cart.entity.Cart; +import com.fc.shimpyo_be.domain.cart.repository.CartRepository; import com.fc.shimpyo_be.domain.member.entity.Authority; import com.fc.shimpyo_be.domain.member.entity.Member; import com.fc.shimpyo_be.domain.member.exception.MemberNotFoundException; @@ -55,15 +57,24 @@ public class ReservationServiceTest extends AbstractContainersSupport { @Autowired private RoomRepository roomRepository; + @Autowired + private CartRepository cartRepository; + @Autowired private DatabaseCleanUp databaseCleanUp; private Member member; private final String[] tableNameArray = { - "member", "product", "room", "product_option", "address", "room_option", "amenity" + "member", "product", "room", "product_option", "address", "room_option", "amenity", "cart" }; + private LocalDate startDate1 = LocalDate.now().plusDays(1); + private LocalDate endDate1 = startDate1.plusDays(2); + + private LocalDate startDate2 = LocalDate.now().plusMonths(2); + private LocalDate endDate2 = startDate2.plusDays(3); + @BeforeEach void setUp() { databaseCleanUp.cleanUp(tableNameArray); @@ -134,6 +145,7 @@ void setUp() { rooms.add( roomRepository.save( Room.builder() + .code(1000 + i) .product(products.get(i - 1)) .name(roomName) .description(roomName + " 설명") @@ -171,6 +183,26 @@ void setUp() { ) ); } + + cartRepository.save( + Cart.builder() + .member(member) + .roomCode(rooms.get(0).getCode()) + .startDate(startDate1) + .endDate(endDate1) + .price(150000L) + .build() + ); + + cartRepository.save( + Cart.builder() + .member(member) + .roomCode(rooms.get(1).getCode()) + .startDate(startDate2) + .endDate(endDate2) + .price(200000L) + .build() + ); } @DisplayName("정상적으로 예약을 저장할 수 있다.") @@ -185,10 +217,10 @@ void saveReservation_test() { = new SaveReservationRequestDto( List.of( new ReservationProductRequestDto( - roomId1, "2023-11-20", "2023-11-23", + 1L, roomId1, startDate1.toString(), endDate1.toString(), "visitor1", "010-1111-1111", 150000), new ReservationProductRequestDto( - roomId2, "2023-11-26", "2023-11-30", + 2L, roomId2, startDate2.toString(), endDate2.toString(), "visitor1", "010-1111-1111", 200000 ) ), PayMethod.CREDIT_CARD, 350000 @@ -208,6 +240,42 @@ void saveReservation_test() { //then assertThat(result.reservationId()).isNotNull(); assertThat(result.reservationProducts()).hasSize(2); + assertThat(cartRepository.findById(1L)).isNotPresent(); + assertThat(cartRepository.findById(2L)).isNotPresent(); + } + + @DisplayName("예약 저장시 장바구니 식별자가 -1인 경우는 장바구니 아이템을 삭제하지 않는다.") + @Test + void saveReservation_cart_delete_filter_test() { + //given + long memberId = member.getId(); + long roomId1 = 1L; + long cartId1 = -1L; + + SaveReservationRequestDto requestDto + = new SaveReservationRequestDto( + List.of( + new ReservationProductRequestDto( + cartId1, roomId1, startDate1.toString(), endDate1.toString(), + "visitor1", "010-1111-1111", 150000) + ), PayMethod.CREDIT_CARD, 150000 + ); + + Map> map = new HashMap<>(); + for (ReservationProductRequestDto reservationProduct : requestDto.reservationProducts()) { + map.put( + reservationProduct.roomId(), + getKeyList(reservationProduct.roomId(), reservationProduct.startDate(), reservationProduct.endDate()) + ); + } + + //when + SaveReservationResponseDto result = reservationService.saveReservation(memberId, requestDto, map); + + //then + assertThat(result.reservationId()).isNotNull(); + assertThat(result.reservationProducts()).hasSize(1); + assertThat(cartRepository.findAll()).hasSize(2); } @DisplayName("회원이 존재하지 않으면 예약을 저장할 수 없다.") @@ -222,11 +290,12 @@ void saveReservation_memberNotFound_test() { = new SaveReservationRequestDto( List.of( new ReservationProductRequestDto( - roomId1, "2023-11-20", "2023-11-23", + 1L, roomId1, startDate1.toString(), endDate1.toString(), "visitor1", "010-1111-1111", 150000), new ReservationProductRequestDto( - roomId2, "2023-11-18", "2023-11-20", - "visitor2", "010-2222-2222", 200000) + 2L, roomId2, startDate2.toString(), endDate2.toString(), + "visitor1", "010-1111-1111", 200000 + ) ), PayMethod.CREDIT_CARD, 350000 ); @@ -255,11 +324,12 @@ void saveReservation_roomNotFound_test() { = new SaveReservationRequestDto( List.of( new ReservationProductRequestDto( - roomId1, "2023-11-20", "2023-11-23", + 1L, roomId1, startDate1.toString(), endDate1.toString(), "visitor1", "010-1111-1111", 150000), new ReservationProductRequestDto( - roomId2, "2023-11-18", "2023-11-20", - "visitor2", "010-2222-2222", 200000) + 2L, roomId2, startDate2.toString(), endDate2.toString(), + "visitor1", "010-1111-1111", 200000 + ) ), PayMethod.CREDIT_CARD, 350000 ); From 118f6a8563eb4db1a6f92dde1434cc27db05bd77 Mon Sep 17 00:00:00 2001 From: jo0oy Date: Thu, 14 Dec 2023 11:16:31 +0900 Subject: [PATCH 13/26] =?UTF-8?q?#127=20test:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B3=BC=20=EC=98=88=EC=95=BD=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=9D=98=20Request/Response=20DTO=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Docs=20Test=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/ReservationRestControllerDocsTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/fc/shimpyo_be/domain/reservation/docs/ReservationRestControllerDocsTest.java b/src/test/java/com/fc/shimpyo_be/domain/reservation/docs/ReservationRestControllerDocsTest.java index bf6f6512..1dee7527 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/reservation/docs/ReservationRestControllerDocsTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/reservation/docs/ReservationRestControllerDocsTest.java @@ -84,6 +84,7 @@ void saveReservation() throws Exception { .reservationProducts( List.of( ReservationProductRequestDto.builder() + .cartId(2L) .roomId(1L) .startDate("2023-11-20") .endDate("2023-11-23") @@ -92,6 +93,7 @@ void saveReservation() throws Exception { .price(300000) .build(), ReservationProductRequestDto.builder() + .cartId(7L) .roomId(2L) .startDate("2023-12-10") .endDate("2023-12-12") @@ -159,6 +161,9 @@ void saveReservation() throws Exception { fieldWithPath("reservationProducts").type(JsonFieldType.ARRAY).description("예약할 객실 숙소 리스트") .attributes(key("constraints").value( saveReservationDescriptions.descriptionsForProperty("reservationProducts"))), + fieldWithPath("reservationProducts[].cartId").type(JsonFieldType.NUMBER).description("장바구니 식별자") + .attributes(key("constraints").value( + reservationProductDescriptions.descriptionsForProperty("cartId"))), fieldWithPath("reservationProducts[].roomId").type(JsonFieldType.NUMBER).description("예약할 객실 식별자") .attributes(key("constraints").value( reservationProductDescriptions.descriptionsForProperty("roomId"))), @@ -319,10 +324,10 @@ void checkAvailableAndPreoccupy() throws Exception { .rooms( List.of( PreoccupyRoomItemRequestDto.builder() - .roomCode(1001L).startDate("2023-12-23").endDate("2023-12-25") + .cartId(1L).roomCode(1001L).startDate("2023-12-23").endDate("2023-12-25") .build(), PreoccupyRoomItemRequestDto.builder() - .roomCode(1002L).startDate("2023-11-11").endDate("2023-11-14") + .cartId(2L).roomCode(1002L).startDate("2023-11-11").endDate("2023-11-14") .build() ) ) @@ -334,12 +339,14 @@ void checkAvailableAndPreoccupy() throws Exception { .roomResults( List.of( ValidatePreoccupyRoomResponseDto.builder() + .cartId(1L) .roomCode(1001L) .startDate("2023-12-23") .endDate("2023-12-25") .roomId(1L) .build(), ValidatePreoccupyRoomResponseDto.builder() + .cartId(2L) .roomCode(1002L) .startDate("2023-11-11") .endDate("2023-11-14") @@ -364,6 +371,9 @@ void checkAvailableAndPreoccupy() throws Exception { fieldWithPath("rooms").type(JsonFieldType.ARRAY).description("예약할 객실 리스트") .attributes(key("constraints").value( preoccupyRoomsDescriptions.descriptionsForProperty("rooms"))), + fieldWithPath("rooms[].cartId").type(JsonFieldType.NUMBER).description("장바구니 식별자") + .attributes(key("constraints").value( + preoccupyRoomItemDescriptions.descriptionsForProperty("cartId"))), fieldWithPath("rooms[].roomCode").type(JsonFieldType.NUMBER).description("예약할 객실 코드") .attributes(key("constraints").value( preoccupyRoomItemDescriptions.descriptionsForProperty("roomCode"))), @@ -378,6 +388,7 @@ void checkAvailableAndPreoccupy() throws Exception { fieldWithPath("data").type(JsonFieldType.OBJECT).description("응답 데이터"), fieldWithPath("data.isAvailable").type(JsonFieldType.BOOLEAN).description("예약 선점 가능 여부"), fieldWithPath("data.roomResults").type(JsonFieldType.ARRAY).description("객실별 예약 선점 가능 검증 결과 리스트"), + fieldWithPath("data.roomResults[].cartId").type(JsonFieldType.NUMBER).description("장바구니 식별자"), fieldWithPath("data.roomResults[].roomCode").type(JsonFieldType.NUMBER).description("객실 코드"), fieldWithPath("data.roomResults[].startDate").type(JsonFieldType.STRING).description("숙박 시작일"), fieldWithPath("data.roomResults[].endDate").type(JsonFieldType.STRING).description("숙박 마지막일"), From 433cb4ac53c5188db65523f4207a04dd1983e694 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 14:54:51 +0900 Subject: [PATCH 14/26] =?UTF-8?q?refactor:=20Open=20API=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/service/OpenApiService.java | 43 ++++++------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java b/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java index a579b4b9..94918113 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java +++ b/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java @@ -22,7 +22,6 @@ import java.nio.charset.StandardCharsets; import java.time.LocalTime; import java.util.ArrayList; -import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.json.JSONArray; @@ -70,8 +69,7 @@ public void init() { @Transactional public void getData(int pageSize, int pageNum) throws JSONException { try { - JSONArray stayArr = getAccommodation(pageSize, pageNum).getJSONObject("items") - .getJSONArray("item"); + JSONArray stayArr = getItems(getAccommodation(pageSize, pageNum)); for (int j = 0; j < stayArr.length(); j++) { try { @@ -96,12 +94,13 @@ public void getData(int pageSize, int pageNum) throws JSONException { saveProductImages(product, images); saveRooms(product, introItem, rooms); } catch (InvalidDataException e) { + log.debug("[OpenAPI] " + stayArr); log.error(e.getMessage()); - log.info("다음 숙소를 조회합니다."); + log.info("[OpenAPI] 다음 숙소를 조회합니다."); } } } catch (Exception e) { - log.error(e.getMessage()); + log.error("[OpenAPI] " + e.getMessage()); throw new OpenApiException(); } } @@ -128,11 +127,7 @@ private JSONObject getAccommodation(int pageSize, int pageNum) throws JSONExcept .build(true).toUri(); ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class); - log.info("숙박 정보 조회"); - log.info(response.toString()); - return new JSONObject(response.getBody()) - .getJSONObject("response") - .getJSONObject("body"); + return getBody(response.getBody()); } private JSONObject getCommon(long contentId) throws JSONException { @@ -148,10 +143,7 @@ private JSONObject getCommon(long contentId) throws JSONException { .build(true).toUri(); ResponseEntity commonResponse = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class); - log.info(contentId + "번 데이터 공통 정보 조회" + commonResponse.getBody()); - return new JSONObject(commonResponse.getBody()) - .getJSONObject("response") - .getJSONObject("body"); + return getBody(commonResponse.getBody()); } private JSONObject getIntro(long contentId) throws JSONException { @@ -162,10 +154,7 @@ private JSONObject getIntro(long contentId) throws JSONException { .build(true).toUri(); ResponseEntity introResponse = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class); - log.info(contentId + "번 데이터 소개 정보 조회" + introResponse.getBody()); - return new JSONObject(introResponse.getBody()) - .getJSONObject("response") - .getJSONObject("body"); + return getBody(introResponse.getBody()); } private JSONObject getInfo(long contentId) throws JSONException { @@ -176,10 +165,7 @@ private JSONObject getInfo(long contentId) throws JSONException { .build(true).toUri(); ResponseEntity infoResponse = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class); - log.info(contentId + "번 데이터 반복 정보 조회" + infoResponse.getBody()); - return new JSONObject(infoResponse.getBody()) - .getJSONObject("response") - .getJSONObject("body"); + return getBody(infoResponse.getBody()); } private JSONObject getImages(long contentId) throws JSONException { @@ -191,16 +177,17 @@ private JSONObject getImages(long contentId) throws JSONException { .build(true).toUri(); ResponseEntity imageResponse = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class); - log.info(contentId + "번 데이터 이미지 정보 조회" + imageResponse.getBody()); - return new JSONObject(imageResponse.getBody()) - .getJSONObject("response") - .getJSONObject("body"); + return getBody(imageResponse.getBody()); } private JSONArray getItems(JSONObject jsonObject) { return jsonObject.getJSONObject("items").getJSONArray("item"); } + private JSONObject getBody(String source) { + return new JSONObject(source).getJSONObject("response").getJSONObject("body"); + } + private boolean hasRoom(JSONArray info) throws JSONException { boolean hasRoom = false; for (int i = 0; i < info.length(); i++) { @@ -234,7 +221,6 @@ private Product saveProduct(JSONObject base, JSONObject common, JSONObject intro .sports(intro.get("sports").equals("1")) .seminar(intro.get("seminar").equals("1")) .build(); - Product product = Product.builder() .name(base.getString("title")) .address( @@ -257,7 +243,6 @@ private Product saveProduct(JSONObject base, JSONObject common, JSONObject intro } private void saveProductImages(Product product, JSONArray images) { - List productImages = new ArrayList<>(); for (int k = 0; k < images.length(); k++) { productImageRepository.save(ProductImage.builder() .product(product) @@ -274,13 +259,11 @@ private void saveRooms(Product product, JSONObject intro, JSONArray info) throws } if (Integer.parseInt(roomJson.getString("roomcount")) != 0) { for (int j = 0; j < Integer.parseInt(roomJson.getString("roomcount")); j++) { - System.out.println(intro.toString()); String[] stringCheckIn = intro.getString("checkintime").split(":|;|시"); String[] stringCheckOut = intro.getString("checkouttime").split(":|;|시"); LocalTime checkIn = getTimeFromString(stringCheckIn); LocalTime checkOut = getTimeFromString(stringCheckOut); - System.out.println(roomJson); RoomPrice roomPrice = RoomPrice.builder() .offWeekDaysMinFee(Integer.parseInt( roomJson.getString("roomoffseasonminfee1"))) From d09525395304f8544d21d7e3e6292f7f23a03e3f Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 15:10:15 +0900 Subject: [PATCH 15/26] =?UTF-8?q?refactor:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=20=EB=A0=88=EB=B2=A8=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/dto/request/CheckPasswordRequestDto.java | 5 +++-- .../domain/member/dto/request/RefreshRequestDto.java | 5 +++-- .../domain/member/dto/request/SignInRequestDto.java | 8 ++++---- .../domain/member/dto/request/SignUpRequestDto.java | 5 +++-- .../domain/member/dto/request/UpdateMemberRequestDto.java | 5 +++-- .../domain/member/dto/response/MemberResponseDto.java | 5 +++-- .../domain/member/dto/response/SignInResponseDto.java | 5 +++-- .../domain/member/dto/response/TokenResponseDto.java | 5 +++-- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/CheckPasswordRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/CheckPasswordRequestDto.java index af1324bc..0bfafe93 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/CheckPasswordRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/CheckPasswordRequestDto.java @@ -1,19 +1,20 @@ package com.fc.shimpyo_be.domain.member.dto.request; import jakarta.validation.constraints.NotBlank; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class CheckPasswordRequestDto { @NotBlank(message = "비밀번호를 입력하세요.") private String password; @Builder - public CheckPasswordRequestDto(String password) { + private CheckPasswordRequestDto(String password) { this.password = password; } } diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/RefreshRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/RefreshRequestDto.java index 3523d5d6..740aecb6 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/RefreshRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/RefreshRequestDto.java @@ -1,12 +1,13 @@ package com.fc.shimpyo_be.domain.member.dto.request; import jakarta.validation.constraints.NotBlank; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class RefreshRequestDto { @NotBlank(message = "Access Token 을 입력하세요.") @@ -15,7 +16,7 @@ public class RefreshRequestDto { private String refreshToken; @Builder - public RefreshRequestDto(String accessToken, String refreshToken) { + private RefreshRequestDto(String accessToken, String refreshToken) { this.accessToken = accessToken; this.refreshToken = refreshToken; } diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignInRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignInRequestDto.java index ea765cdf..4be9b0e6 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignInRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignInRequestDto.java @@ -2,14 +2,14 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; -import jakarta.validation.constraints.Size; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class SignInRequestDto { @NotBlank(message = "이메일을 입력하세요.") @@ -19,12 +19,12 @@ public class SignInRequestDto { private String password; @Builder - public SignInRequestDto(String email, String password) { + private SignInRequestDto(String email, String password) { this.email = email; this.password = password; } - public UsernamePasswordAuthenticationToken toAuthentication(){ + public UsernamePasswordAuthenticationToken toAuthentication() { return new UsernamePasswordAuthenticationToken(this.email, this.password); } } diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java index 30dedcd0..0c64bcc9 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java @@ -5,13 +5,14 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class SignUpRequestDto { @NotBlank(message = "이메일을 입력하세요.") @@ -26,7 +27,7 @@ public class SignUpRequestDto { private String passwordConfirm; @Builder - public SignUpRequestDto(String email, String name, String password, String passwordConfirm) { + private SignUpRequestDto(String email, String name, String password, String passwordConfirm) { this.email = email; this.name = name; this.password = password; diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/UpdateMemberRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/UpdateMemberRequestDto.java index 0bef7927..445f874f 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/UpdateMemberRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/UpdateMemberRequestDto.java @@ -1,11 +1,12 @@ package com.fc.shimpyo_be.domain.member.dto.request; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class UpdateMemberRequestDto { private String password; @@ -13,7 +14,7 @@ public class UpdateMemberRequestDto { private String photoUrl; @Builder - public UpdateMemberRequestDto(String password, String passwordConfirm, String photoUrl) { + private UpdateMemberRequestDto(String password, String passwordConfirm, String photoUrl) { this.password = password; this.passwordConfirm = passwordConfirm; this.photoUrl = photoUrl; diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/MemberResponseDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/MemberResponseDto.java index 949a10c4..aa80ac89 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/MemberResponseDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/MemberResponseDto.java @@ -1,12 +1,13 @@ package com.fc.shimpyo_be.domain.member.dto.response; import com.fc.shimpyo_be.domain.member.entity.Member; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class MemberResponseDto { private Long memberId; @@ -15,7 +16,7 @@ public class MemberResponseDto { private String photoUrl; @Builder - public MemberResponseDto(Long memberId, String email, String name, String photoUrl) { + private MemberResponseDto(Long memberId, String email, String name, String photoUrl) { this.memberId = memberId; this.email = email; this.name = name; diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/SignInResponseDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/SignInResponseDto.java index 89fd6040..352c70cd 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/SignInResponseDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/SignInResponseDto.java @@ -1,18 +1,19 @@ package com.fc.shimpyo_be.domain.member.dto.response; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class SignInResponseDto { private MemberResponseDto member; private TokenResponseDto token; @Builder - public SignInResponseDto(MemberResponseDto member, TokenResponseDto token) { + private SignInResponseDto(MemberResponseDto member, TokenResponseDto token) { this.member = member; this.token = token; } diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/TokenResponseDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/TokenResponseDto.java index 582a440b..7d5ce9f5 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/TokenResponseDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/response/TokenResponseDto.java @@ -1,11 +1,12 @@ package com.fc.shimpyo_be.domain.member.dto.response; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class TokenResponseDto { private String grantType; @@ -14,7 +15,7 @@ public class TokenResponseDto { private String refreshToken; @Builder - public TokenResponseDto(String grantType, String accessToken, long accessTokenExpiresIn, + private TokenResponseDto(String grantType, String accessToken, long accessTokenExpiresIn, String refreshToken) { this.grantType = grantType; this.accessToken = accessToken; From 29410b614469bbccaa03b8eb68e40db6cb484583 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 15:10:36 +0900 Subject: [PATCH 16/26] =?UTF-8?q?test:=20=EC=A3=BC=EC=84=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/docs/AuthRestControllerDocsTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fc/shimpyo_be/domain/member/docs/AuthRestControllerDocsTest.java b/src/test/java/com/fc/shimpyo_be/domain/member/docs/AuthRestControllerDocsTest.java index a3208c56..e4350f54 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/member/docs/AuthRestControllerDocsTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/member/docs/AuthRestControllerDocsTest.java @@ -57,7 +57,7 @@ void signUp() throws Exception { given(authService.signUp(any(SignUpRequestDto.class))).willReturn(memberResponseDto); - // when + // when then mockMvc.perform(post("/api/auth/signup") .content(objectMapper.writeValueAsString(signUpRequestDto)) .contentType(MediaType.APPLICATION_JSON)) @@ -118,7 +118,7 @@ void signIn() throws Exception { given(authService.signIn(any(SignInRequestDto.class))).willReturn(signInResponseDto); - // when + // when then mockMvc.perform(post("/api/auth/signin") .content(objectMapper.writeValueAsString(signInRequestDto)) .contentType(MediaType.APPLICATION_JSON)) @@ -187,7 +187,7 @@ void refresh() throws Exception { given(authService.refresh(any(RefreshRequestDto.class))).willReturn(signInResponseDto); - // when + // when then mockMvc.perform(post("/api/auth/refresh") .content(objectMapper.writeValueAsString(refreshRequestDto)) .contentType(MediaType.APPLICATION_JSON)) From a0a74e9b4473103bd9ae6313587561844718eb77 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 15:21:12 +0900 Subject: [PATCH 17/26] =?UTF-8?q?test:=20=EC=A6=90=EA=B2=A8=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=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 --- .../docs/FavoriteRestControllerDocsTest.java | 8 ++++---- .../controller/FavoriteRestControllerTest.java | 15 ++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/fc/shimpyo_be/domain/favorite/docs/FavoriteRestControllerDocsTest.java b/src/test/java/com/fc/shimpyo_be/domain/favorite/docs/FavoriteRestControllerDocsTest.java index f8d8740d..1c99e2f0 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/favorite/docs/FavoriteRestControllerDocsTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/favorite/docs/FavoriteRestControllerDocsTest.java @@ -46,8 +46,8 @@ void register() throws Exception { .build(); given(securityUtil.getCurrentMemberId()).willReturn(1L); - given(favoriteService.register(any(Long.TYPE), any(Long.TYPE))).willReturn( - favoriteResponseDto); + given(favoriteService.register(any(Long.TYPE), any(Long.TYPE))) + .willReturn(favoriteResponseDto); // when then mockMvc.perform(post("/api/favorites/{productId}", 1L)) @@ -141,8 +141,8 @@ void cancel() throws Exception { .build(); given(securityUtil.getCurrentMemberId()).willReturn(1L); - given(favoriteService.delete(any(Long.TYPE), any(Long.TYPE))).willReturn( - favoriteResponseDto); + given(favoriteService.delete(any(Long.TYPE), any(Long.TYPE))) + .willReturn(favoriteResponseDto); // when then mockMvc.perform(delete("/api/favorites/{productId}", 1L)) diff --git a/src/test/java/com/fc/shimpyo_be/domain/favorite/unit/controller/FavoriteRestControllerTest.java b/src/test/java/com/fc/shimpyo_be/domain/favorite/unit/controller/FavoriteRestControllerTest.java index 96ddcf62..456fe806 100644 --- a/src/test/java/com/fc/shimpyo_be/domain/favorite/unit/controller/FavoriteRestControllerTest.java +++ b/src/test/java/com/fc/shimpyo_be/domain/favorite/unit/controller/FavoriteRestControllerTest.java @@ -10,7 +10,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fc.shimpyo_be.config.AbstractContainersSupport; import com.fc.shimpyo_be.domain.favorite.dto.FavoriteResponseDto; import com.fc.shimpyo_be.domain.favorite.dto.FavoritesResponseDto; @@ -49,8 +48,6 @@ public class FavoriteRestControllerTest extends AbstractContainersSupport { @MockBean SecurityUtil securityUtil; - ObjectMapper objectMapper = new ObjectMapper(); - @BeforeEach public void setup() { mockMvc = MockMvcBuilders @@ -75,8 +72,8 @@ void _willSuccess() throws Exception { .build(); given(securityUtil.getCurrentMemberId()).willReturn(1L); - given(favoriteService.register(any(Long.TYPE), any(Long.TYPE))).willReturn( - favoriteResponseDto); + given(favoriteService.register(any(Long.TYPE), any(Long.TYPE))) + .willReturn(favoriteResponseDto); // when then mockMvc.perform(post("/api/favorites/{productId}", 1L)) @@ -117,8 +114,8 @@ void _willSuccess() throws Exception { .build(); given(securityUtil.getCurrentMemberId()).willReturn(1L); - given(favoriteService.getFavorites(any(Long.TYPE), any(Pageable.class))).willReturn( - favoritesResponseDto); + given(favoriteService.getFavorites(any(Long.TYPE), any(Pageable.class))) + .willReturn(favoritesResponseDto); // when then mockMvc.perform(get("/api/favorites") @@ -158,8 +155,8 @@ void _willSuccess() throws Exception { .build(); given(securityUtil.getCurrentMemberId()).willReturn(1L); - given(favoriteService.delete(any(Long.TYPE), any(Long.TYPE))).willReturn( - favoriteResponseDto); + given(favoriteService.delete(any(Long.TYPE), any(Long.TYPE))) + .willReturn(favoriteResponseDto); // when then mockMvc.perform(delete("/api/favorites/{productId}", 1L)) From 1dccde30e9e8bc1d00bf8c7b183be5ba089f8dca Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 15:24:25 +0900 Subject: [PATCH 18/26] =?UTF-8?q?refactor:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=20=EB=A0=88=EB=B2=A8=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shimpyo_be/domain/favorite/dto/FavoriteResponseDto.java | 5 +++-- .../shimpyo_be/domain/favorite/dto/FavoritesResponseDto.java | 5 +++-- .../com/fc/shimpyo_be/domain/favorite/entity/Favorite.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoriteResponseDto.java b/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoriteResponseDto.java index 55ca2b2e..6594df31 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoriteResponseDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoriteResponseDto.java @@ -1,12 +1,13 @@ package com.fc.shimpyo_be.domain.favorite.dto; import com.fc.shimpyo_be.domain.favorite.entity.Favorite; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class FavoriteResponseDto { private Long favoriteId; @@ -14,7 +15,7 @@ public class FavoriteResponseDto { private Long productId; @Builder - public FavoriteResponseDto(Long favoriteId, Long memberId, Long productId) { + private FavoriteResponseDto(Long favoriteId, Long memberId, Long productId) { this.favoriteId = favoriteId; this.memberId = memberId; this.productId = productId; diff --git a/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoritesResponseDto.java b/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoritesResponseDto.java index 214e574a..9c45db18 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoritesResponseDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/favorite/dto/FavoritesResponseDto.java @@ -2,19 +2,20 @@ import com.fc.shimpyo_be.domain.product.dto.response.ProductResponse; import java.util.List; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class FavoritesResponseDto { private int pageCount; private List products; @Builder - public FavoritesResponseDto(int pageCount, List products) { + private FavoritesResponseDto(int pageCount, List products) { this.pageCount = pageCount; this.products = products; } diff --git a/src/main/java/com/fc/shimpyo_be/domain/favorite/entity/Favorite.java b/src/main/java/com/fc/shimpyo_be/domain/favorite/entity/Favorite.java index d1d493ea..d4c10bf2 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/favorite/entity/Favorite.java +++ b/src/main/java/com/fc/shimpyo_be/domain/favorite/entity/Favorite.java @@ -30,7 +30,7 @@ public class Favorite { private Product product; @Builder - public Favorite(Long id, Member member, Product product) { + private Favorite(Long id, Member member, Product product) { this.id = id; this.member = member; this.product = product; From 4fdd94588f03d199eb9c8cefbb1ab11b0ece8a37 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 15:27:44 +0900 Subject: [PATCH 19/26] =?UTF-8?q?refactor:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=20=EB=A0=88=EB=B2=A8=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fc/shimpyo_be/domain/member/entity/Member.java | 2 +- .../com/fc/shimpyo_be/domain/member/entity/RefreshToken.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/entity/Member.java b/src/main/java/com/fc/shimpyo_be/domain/member/entity/Member.java index bf843d32..94917b07 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/entity/Member.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/entity/Member.java @@ -41,7 +41,7 @@ public class Member extends BaseTimeEntity { private Authority authority; @Builder - public Member(Long id, String email, String name, String password, String photoUrl, + private Member(Long id, String email, String name, String password, String photoUrl, Authority authority) { this.id = id; this.email = email; diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/entity/RefreshToken.java b/src/main/java/com/fc/shimpyo_be/domain/member/entity/RefreshToken.java index 2d194fec..211d0864 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/entity/RefreshToken.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/entity/RefreshToken.java @@ -20,7 +20,7 @@ public class RefreshToken { private String token; @Builder - public RefreshToken(Long id, String token) { + private RefreshToken(Long id, String token) { this.id = id; this.token = token; } From afccce466f5481869ecb602b8cfdb3b68d19b92a Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:20:36 +0900 Subject: [PATCH 20/26] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=84=B4=EA=B3=BC?= =?UTF-8?q?=20min,=20max=20=EC=83=81=EC=88=98=EB=A1=9C=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=ED=95=98=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/member/dto/request/SignUpRequestDto.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java index 0c64bcc9..3f7bb9ac 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java @@ -15,11 +15,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class SignUpRequestDto { + private final String emailRegexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; + private final int nameMin = 2; + private final int nameMax = 30; + @NotBlank(message = "이메일을 입력하세요.") - @Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "이메일 형식에 맞게 입력해주세요.") + @Pattern(regexp = emailRegexp, message = "이메일 형식에 맞게 입력해주세요.") private String email; @NotBlank(message = "이름을 입력하세요.") - @Size(min = 2, max = 30, message = "이름은 최소 2자 이상 최대 30자 이내로 입력하세요.") + @Size(min = nameMin, max = nameMax, message = "이름은 최소 2자 이상 최대 30자 이내로 입력하세요.") private String name; @NotBlank(message = "비밀번호를 입력하세요.") private String password; From 0b1e31f02451b688dfe8b951b66a0df7b03e1e9c Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:25:19 +0900 Subject: [PATCH 21/26] =?UTF-8?q?refactor:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=ED=8C=A8=ED=84=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shimpyo_be/domain/member/dto/request/SignUpRequestDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java index 3f7bb9ac..77470d55 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java @@ -16,6 +16,7 @@ public class SignUpRequestDto { private final String emailRegexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; + private final String passwordRegexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$#^()!%*?&])[A-Za-z\\d@$!#^()%*?&]{8,30}$"; private final int nameMin = 2; private final int nameMax = 30; @@ -26,8 +27,10 @@ public class SignUpRequestDto { @Size(min = nameMin, max = nameMax, message = "이름은 최소 2자 이상 최대 30자 이내로 입력하세요.") private String name; @NotBlank(message = "비밀번호를 입력하세요.") + @Pattern(regexp = passwordRegexp) private String password; @NotBlank(message = "비밀번호 확인을 입력하세요.") + @Pattern(regexp = passwordRegexp) private String passwordConfirm; @Builder From 55e68448a50e2854a2ac6437c35d87eca5a04721 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:29:12 +0900 Subject: [PATCH 22/26] =?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=B9=85=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fc/shimpyo_be/domain/product/service/OpenApiService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java b/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java index 94918113..63593ce3 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java +++ b/src/main/java/com/fc/shimpyo_be/domain/product/service/OpenApiService.java @@ -94,9 +94,7 @@ public void getData(int pageSize, int pageNum) throws JSONException { saveProductImages(product, images); saveRooms(product, introItem, rooms); } catch (InvalidDataException e) { - log.debug("[OpenAPI] " + stayArr); log.error(e.getMessage()); - log.info("[OpenAPI] 다음 숙소를 조회합니다."); } } } catch (Exception e) { From 7c9771e209b821f69521296372ca27eb6e17d354 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:31:23 +0900 Subject: [PATCH 23/26] =?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=B9=85=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favorite/controller/FavoriteRestController.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java b/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java index 866fee22..484f62db 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java +++ b/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java @@ -8,7 +8,6 @@ import com.fc.shimpyo_be.global.common.ResponseDto; import com.fc.shimpyo_be.global.util.SecurityUtil; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; @@ -20,7 +19,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/api/favorites") @@ -28,10 +26,11 @@ public class FavoriteRestController { private final FavoriteService favoriteService; private final SecurityUtil securityUtil; + private final int size = 10; + private final int page = 0; @PostMapping("/{productId}") public ResponseEntity> register(@PathVariable long productId) { - log.debug("memberId: {}, productId: {}", securityUtil.getCurrentMemberId(), productId); return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDto.res(HttpStatus.CREATED, favoriteService.register(securityUtil.getCurrentMemberId(), productId), "성공적으로 즐겨찾기를 등록했습니다.")); @@ -39,8 +38,7 @@ public ResponseEntity> register(@PathVariable l @GetMapping public ResponseEntity> getFavorites( - @PageableConstraint(Favorite.class) @PageableDefault(size = 10, page = 0) Pageable pageable) { - log.debug("memberId: {}", securityUtil.getCurrentMemberId()); + @PageableConstraint(Favorite.class) @PageableDefault(size = size, page = page) Pageable pageable) { return ResponseEntity.status(HttpStatus.OK) .body(ResponseDto.res(HttpStatus.OK, favoriteService.getFavorites( securityUtil.getCurrentMemberId(), pageable), "성공적으로 즐겨찾기 목록을 조회했습니다.")); @@ -48,7 +46,6 @@ public ResponseEntity> getFavorites( @DeleteMapping("/{productId}") public ResponseEntity> cancel(@PathVariable long productId) { - log.debug("memberId: {}, productId: {}", securityUtil.getCurrentMemberId(), productId); return ResponseEntity.status(HttpStatus.OK).body(ResponseDto.res(HttpStatus.OK, favoriteService.delete(securityUtil.getCurrentMemberId(), productId), "성공적으로 즐겨찾기를 취소했습니다.")); From f8f01af1ac884dab975828eaeedbb9e1e3fd10e6 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:45:36 +0900 Subject: [PATCH 24/26] =?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=B9=85=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/AuthRestController.java | 6 ------ .../domain/member/controller/MemberRestController.java | 5 ----- 2 files changed, 11 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/controller/AuthRestController.java b/src/main/java/com/fc/shimpyo_be/domain/member/controller/AuthRestController.java index 07744978..d62db927 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/controller/AuthRestController.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/controller/AuthRestController.java @@ -9,7 +9,6 @@ import com.fc.shimpyo_be.global.common.ResponseDto; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/api/auth") @@ -28,7 +26,6 @@ public class AuthRestController { @PostMapping("/signup") public ResponseEntity> signUp( @Valid @RequestBody SignUpRequestDto signUpRequestDto) { - log.debug("email: {}, name: {}", signUpRequestDto.getEmail(), signUpRequestDto.getName()); return ResponseEntity.status(HttpStatus.CREATED).body( ResponseDto.res(HttpStatus.CREATED, authService.signUp(signUpRequestDto), "성공적으로 회원가입 했습니다.")); @@ -37,7 +34,6 @@ public ResponseEntity> signUp( @PostMapping("/signin") public ResponseEntity> signIn( @Valid @RequestBody SignInRequestDto signInRequestDto) { - log.debug("email: {}", signInRequestDto.getEmail()); return ResponseEntity.status(HttpStatus.OK).body( ResponseDto.res(HttpStatus.OK, authService.signIn(signInRequestDto), "성공적으로 로그인 했습니다.")); @@ -46,8 +42,6 @@ public ResponseEntity> signIn( @PostMapping("/refresh") public ResponseEntity> refresh( @Valid @RequestBody RefreshRequestDto refreshRequestDto) { - log.debug("accessToken: {}, refreshToken: {}", refreshRequestDto.getAccessToken(), - refreshRequestDto.getRefreshToken()); return ResponseEntity.status(HttpStatus.OK).body( ResponseDto.res(HttpStatus.OK, authService.refresh(refreshRequestDto), "성공적으로 토큰을 재발급 했습니다.")); diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/controller/MemberRestController.java b/src/main/java/com/fc/shimpyo_be/domain/member/controller/MemberRestController.java index 5393e4eb..629d2e16 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/controller/MemberRestController.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/controller/MemberRestController.java @@ -7,7 +7,6 @@ import com.fc.shimpyo_be.global.common.ResponseDto; import com.fc.shimpyo_be.global.util.SecurityUtil; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/api/members") @@ -28,7 +26,6 @@ public class MemberRestController { @GetMapping public ResponseEntity> getMember() { - log.debug("memberId: {}", securityUtil.getCurrentMemberId()); return ResponseEntity.status(HttpStatus.OK).body( ResponseDto.res(HttpStatus.OK, memberService.getMember(), "성공적으로 회원 정보를 조회했습니다.")); @@ -37,7 +34,6 @@ public ResponseEntity> getMember() { @PatchMapping public ResponseEntity> updateMember(@RequestBody UpdateMemberRequestDto updateMemberRequestDto) { - log.debug("memberId: {}", securityUtil.getCurrentMemberId()); return ResponseEntity.status(HttpStatus.OK).body( ResponseDto.res(HttpStatus.OK, memberService.updateMember(updateMemberRequestDto), "성공적으로 회원 정보를 수정했습니다.")); @@ -46,7 +42,6 @@ public ResponseEntity> updateMember(@RequestBody @PostMapping public ResponseEntity> checkPassword( @RequestBody CheckPasswordRequestDto checkPasswordRequestDto) { - log.debug("memberId: {}", securityUtil.getCurrentMemberId()); memberService.checkPassword(checkPasswordRequestDto); return ResponseEntity.status(HttpStatus.OK).body( ResponseDto.res(HttpStatus.OK, "비밀번호가 일치합니다.")); From a91a0f74342962e69b1e6560c729bfa2aa499d21 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:46:50 +0900 Subject: [PATCH 25/26] =?UTF-8?q?fix:=20=ED=8C=A8=ED=84=B4,=20=EC=B5=9C?= =?UTF-8?q?=EC=86=8C/=EC=B5=9C=EB=8C=80=20=EA=B8=80=EC=9E=90=EC=88=98?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=95=EC=A0=81=20=EC=83=81=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/dto/request/SignUpRequestDto.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java index 77470d55..ed0425f2 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java +++ b/src/main/java/com/fc/shimpyo_be/domain/member/dto/request/SignUpRequestDto.java @@ -15,22 +15,22 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class SignUpRequestDto { - private final String emailRegexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; - private final String passwordRegexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$#^()!%*?&])[A-Za-z\\d@$!#^()%*?&]{8,30}$"; - private final int nameMin = 2; - private final int nameMax = 30; + private static final String EMAIL_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; + private static final int NAME_MIN = 2; + private static final int NAME_MAX = 30; + private static final String PASSWORD_REGEX = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$#^()!%*?&])[A-Za-z\\d@$!#^()%*?&]{8,30}$"; @NotBlank(message = "이메일을 입력하세요.") - @Pattern(regexp = emailRegexp, message = "이메일 형식에 맞게 입력해주세요.") + @Pattern(regexp = EMAIL_REGEX, message = "이메일 형식에 맞게 입력해주세요.") private String email; @NotBlank(message = "이름을 입력하세요.") - @Size(min = nameMin, max = nameMax, message = "이름은 최소 2자 이상 최대 30자 이내로 입력하세요.") + @Size(min = NAME_MIN, max = NAME_MAX, message = "이름은 최소 2자 이상 최대 30자 이내로 입력하세요.") private String name; @NotBlank(message = "비밀번호를 입력하세요.") - @Pattern(regexp = passwordRegexp) + @Pattern(regexp = PASSWORD_REGEX) private String password; @NotBlank(message = "비밀번호 확인을 입력하세요.") - @Pattern(regexp = passwordRegexp) + @Pattern(regexp = PASSWORD_REGEX) private String passwordConfirm; @Builder From 47a94d07f289c20c17bc829ccbb3c9cf6decb1b3 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Thu, 14 Dec 2023 23:49:15 +0900 Subject: [PATCH 26/26] =?UTF-8?q?refactor:=20=ED=8E=98=EC=9D=B4=EC=A7=95?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=20=EC=84=A4=EC=A0=95=EC=9D=84=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=EC=83=81=EC=88=98=EB=A1=9C=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=ED=95=98=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/favorite/controller/FavoriteRestController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java b/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java index 484f62db..9980ffab 100644 --- a/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java +++ b/src/main/java/com/fc/shimpyo_be/domain/favorite/controller/FavoriteRestController.java @@ -26,8 +26,8 @@ public class FavoriteRestController { private final FavoriteService favoriteService; private final SecurityUtil securityUtil; - private final int size = 10; - private final int page = 0; + private static final int DEFAULT_SIZE = 10; + private static final int DEFAULT_PAGE = 0; @PostMapping("/{productId}") public ResponseEntity> register(@PathVariable long productId) { @@ -38,7 +38,7 @@ public ResponseEntity> register(@PathVariable l @GetMapping public ResponseEntity> getFavorites( - @PageableConstraint(Favorite.class) @PageableDefault(size = size, page = page) Pageable pageable) { + @PageableConstraint(Favorite.class) @PageableDefault(size = DEFAULT_SIZE, page = DEFAULT_PAGE) Pageable pageable) { return ResponseEntity.status(HttpStatus.OK) .body(ResponseDto.res(HttpStatus.OK, favoriteService.getFavorites( securityUtil.getCurrentMemberId(), pageable), "성공적으로 즐겨찾기 목록을 조회했습니다."));