From d12754bd8bab8fc441122b33a857685e81d889bc Mon Sep 17 00:00:00 2001 From: rightpair Date: Sat, 27 Jan 2024 18:28:23 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feature]=20CouponUseDaysType=EC=97=90=20AL?= =?UTF-8?q?L=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 설명: - #213 을 참고하세요. --- .../java/com/coolpeace/domain/coupon/dto/DtoCouponUtil.java | 3 +++ src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java | 2 +- .../domain/coupon/entity/type/CouponUseDaysType.java | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/coupon/dto/DtoCouponUtil.java b/src/main/java/com/coolpeace/domain/coupon/dto/DtoCouponUtil.java index a7ddbd7..8ce2f53 100644 --- a/src/main/java/com/coolpeace/domain/coupon/dto/DtoCouponUtil.java +++ b/src/main/java/com/coolpeace/domain/coupon/dto/DtoCouponUtil.java @@ -6,6 +6,9 @@ public class DtoCouponUtil { public static DtoCouponUseDaysType filteringCouponUseConditionDays(CouponUseDaysType couponUseDays) { + if (couponUseDays.equals(CouponUseDaysType.ALL)) { + return null; + } if (couponUseDays.isOneDay()) { return DtoCouponUseDaysType.ONEDAY; } diff --git a/src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java b/src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java index 7951aa4..3b0a463 100644 --- a/src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java +++ b/src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java @@ -62,7 +62,7 @@ public class Coupon extends BaseTimeEntity { private final List couponUseConditionDays = Collections.emptyList(); @Enumerated(EnumType.STRING) - private CouponUseDaysType couponUseDays = CouponUseDaysType.WEEKEND; + private CouponUseDaysType couponUseDays = CouponUseDaysType.ALL; @Column(nullable = false) private LocalDate exposureStartDate; diff --git a/src/main/java/com/coolpeace/domain/coupon/entity/type/CouponUseDaysType.java b/src/main/java/com/coolpeace/domain/coupon/entity/type/CouponUseDaysType.java index b1bd14f..010bb01 100644 --- a/src/main/java/com/coolpeace/domain/coupon/entity/type/CouponUseDaysType.java +++ b/src/main/java/com/coolpeace/domain/coupon/entity/type/CouponUseDaysType.java @@ -15,11 +15,12 @@ public enum CouponUseDaysType implements ValuedEnum { SATURDAY("토"), SUNDAY("일"), WEEKDAY("평일"), - WEEKEND("주말"); + WEEKEND("주말"), + ALL("전체"); private final String value; public boolean isOneDay() { - return !this.equals(WEEKDAY) && !this.equals(WEEKEND); + return !this.equals(WEEKDAY) && !this.equals(WEEKEND) && !this.equals(ALL); } } From ff45064bc4205e7d3ed887ad72c862e26de41801 Mon Sep 17 00:00:00 2001 From: rightpair Date: Sat, 27 Jan 2024 18:28:47 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[feature]=20CouponUseDaysType=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20DTO=20=EB=B0=8F=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/dto/request/CouponRegisterRequest.java | 2 +- .../coolpeace/domain/coupon/dto/response/CouponResponse.java | 4 +++- .../com/coolpeace/domain/coupon/service/CouponService.java | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/coupon/dto/request/CouponRegisterRequest.java b/src/main/java/com/coolpeace/domain/coupon/dto/request/CouponRegisterRequest.java index a19eaed..ede097b 100644 --- a/src/main/java/com/coolpeace/domain/coupon/dto/request/CouponRegisterRequest.java +++ b/src/main/java/com/coolpeace/domain/coupon/dto/request/CouponRegisterRequest.java @@ -44,7 +44,7 @@ public record CouponRegisterRequest( // 쿠폰 사용 조건 Integer minimumReservationPrice, - @ValidEnum(enumClass = DtoCouponUseDaysType.class, message = "올바르지 않은 사용 조건의 날짜 유형입니다.") + @ValidEnum(enumClass = DtoCouponUseDaysType.class, message = "올바르지 않은 사용 조건의 날짜 유형입니다.", required = false) String couponUseConditionDays, @ValidEnum(enumClass = DtoCouponUseDayOfWeekType.class, message = "올바르지 않은 사용 조건의 요일입니다.", required = false) String couponUseConditionDayOfWeek, diff --git a/src/main/java/com/coolpeace/domain/coupon/dto/response/CouponResponse.java b/src/main/java/com/coolpeace/domain/coupon/dto/response/CouponResponse.java index 0a31597..d935757 100644 --- a/src/main/java/com/coolpeace/domain/coupon/dto/response/CouponResponse.java +++ b/src/main/java/com/coolpeace/domain/coupon/dto/response/CouponResponse.java @@ -3,6 +3,7 @@ import com.coolpeace.domain.accommodation.entity.Accommodation; import com.coolpeace.domain.coupon.dto.DtoCouponUtil; import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDayOfWeekType; +import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType; import com.coolpeace.domain.coupon.entity.Coupon; import com.coolpeace.domain.coupon.entity.type.DiscountType; @@ -47,7 +48,8 @@ public static CouponResponse from(Coupon coupon) { coupon.getCustomerType().getValue(), coupon.getCouponRoomTypeStrings(), coupon.getMinimumReservationPrice(), - DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays()).getValue(), + Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays())) + .map(DtoCouponUseDaysType::getValue).orElse(null), Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDayOfWeek(coupon.getCouponUseDays())) .map(DtoCouponUseDayOfWeekType::getValue).orElse(null), coupon.getExposureStartDate(), diff --git a/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java b/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java index b30c96f..370c582 100644 --- a/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java +++ b/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java @@ -27,7 +27,6 @@ import com.coolpeace.domain.room.repository.RoomRepository; import com.coolpeace.global.common.ValuedEnum; import lombok.RequiredArgsConstructor; -import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -35,6 +34,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.time.LocalDate; import java.util.Collections; @@ -145,6 +145,9 @@ public void register(Long memberId, CouponRegisterRequest couponRegisterRequest) } private CouponUseDaysType getCouponUseDays(String couponUseDaysStr, String couponUseDayOfWeekStr) { + if (!StringUtils.hasText(couponUseDaysStr)) { + return CouponUseDaysType.ALL; + } DtoCouponUseDaysType dtoCouponUseDaysType = ValuedEnum.of(DtoCouponUseDaysType.class, couponUseDaysStr); return switch (dtoCouponUseDaysType) { case ONEDAY -> CouponUseDaysType.valueOf( From 8e17978aa093b76a0c4370a7e6fab54e8c2144de Mon Sep 17 00:00:00 2001 From: rightpair Date: Sat, 27 Jan 2024 18:29:19 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[feature]=20CouponUseDaysType=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/coupon/CouponControllerTest.java | 23 +++++++++++-------- .../coupon/service/CouponServiceTest.java | 7 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/coolpeace/docs/coupon/CouponControllerTest.java b/src/test/java/com/coolpeace/docs/coupon/CouponControllerTest.java index 46b9cab..54f18f4 100644 --- a/src/test/java/com/coolpeace/docs/coupon/CouponControllerTest.java +++ b/src/test/java/com/coolpeace/docs/coupon/CouponControllerTest.java @@ -7,6 +7,7 @@ import com.coolpeace.domain.coupon.dto.request.CouponRegisterRequest; import com.coolpeace.domain.coupon.dto.request.CouponUpdateRequest; import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDayOfWeekType; +import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType; import com.coolpeace.domain.coupon.dto.request.type.SearchCouponDateFilterType; import com.coolpeace.domain.coupon.dto.request.type.SearchCouponStatusFilterType; import com.coolpeace.domain.coupon.dto.response.CouponResponse; @@ -114,7 +115,8 @@ void registerCoupon_success() throws Exception { false, randomRoomNumbers, coupon.getMinimumReservationPrice(), - DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays()).getValue(), + Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays())) + .map(DtoCouponUseDaysType::getValue).orElse(null), Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDayOfWeek(coupon.getCouponUseDays())) .map(DtoCouponUseDayOfWeekType::getValue).orElse(null), coupon.getExposureStartDate(), @@ -147,8 +149,8 @@ void registerCoupon_success() throws Exception { fieldWithPath("accommodation_id").type(JsonFieldType.NUMBER).description("숙박업체의 ID"), fieldWithPath("register_all_room").type(JsonFieldType.BOOLEAN).description("객실 등록 여부"), fieldWithPath("register_rooms").type(JsonFieldType.ARRAY).description("등록될 객실의 리스트"), - fieldWithPath("minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격"), - fieldWithPath("coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자"), + fieldWithPath("minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격").optional(), + fieldWithPath("coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자").optional(), fieldWithPath("coupon_use_condition_day_of_week").type(JsonFieldType.STRING).description("쿠폰 사용 가능 요일").optional(), fieldWithPath("exposure_start_date").type(JsonFieldType.STRING).description("노출 시작 날짜"), fieldWithPath("exposure_end_date").type(JsonFieldType.STRING).description("노출 종료 날짜") @@ -211,8 +213,8 @@ void searchCoupon_success() throws Exception { fieldWithPath("content[].maximum_discount_price").type(JsonFieldType.NUMBER).description("정률 할인일 때 최대 할인 한도").optional(), fieldWithPath("content[].customer_type").type(JsonFieldType.STRING).description("고객의 유형"), fieldWithPath("content[].coupon_room_types").type(JsonFieldType.ARRAY).description("객실의 유형"), - fieldWithPath("content[].minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격"), - fieldWithPath("content[].coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자"), + fieldWithPath("content[].minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격").optional(), + fieldWithPath("content[].coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자").optional(), fieldWithPath("content[].coupon_use_condition_day_of_week").type(JsonFieldType.STRING).description("쿠폰 사용 가능 요일").optional(), fieldWithPath("content[].exposure_start_date").type(JsonFieldType.STRING).description("노출 시작 날짜"), fieldWithPath("content[].exposure_end_date").type(JsonFieldType.STRING).description("노출 종료 날짜"), @@ -285,8 +287,8 @@ void getCouponRecentHistory_success() throws Exception { fieldWithPath("[].maximum_discount_price").type(JsonFieldType.NUMBER).description("정률 할인일 때 최대 할인 한도").optional(), fieldWithPath("[].customer_type").type(JsonFieldType.STRING).description("고객의 유형"), fieldWithPath("[].coupon_room_types").type(JsonFieldType.ARRAY).description("객실의 유형"), - fieldWithPath("[].minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격"), - fieldWithPath("[].coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자"), + fieldWithPath("[].minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격").optional(), + fieldWithPath("[].coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자").optional(), fieldWithPath("[].coupon_use_condition_day_of_week").type(JsonFieldType.STRING).description("쿠폰 사용 가능 요일").optional(), fieldWithPath("[].exposure_start_date").type(JsonFieldType.STRING).description("노출 시작 날짜"), fieldWithPath("[].exposure_end_date").type(JsonFieldType.STRING).description("노출 종료 날짜"), @@ -361,8 +363,8 @@ void getCouponByCouponNumber_success() throws Exception { fieldWithPath("maximum_discount_price").type(JsonFieldType.NUMBER).description("정률 할인일 때 최대 할인 한도").optional(), fieldWithPath("customer_type").type(JsonFieldType.STRING).description("고객의 유형"), fieldWithPath("coupon_room_types").type(JsonFieldType.ARRAY).description("객실의 유형"), - fieldWithPath("minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격"), - fieldWithPath("coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자"), + fieldWithPath("minimum_reservation_price").type(JsonFieldType.NUMBER).description("최소 예약 가격").optional(), + fieldWithPath("coupon_use_condition_days").type(JsonFieldType.STRING).description("쿠폰 사용 가능 일자").optional(), fieldWithPath("coupon_use_condition_day_of_week").type(JsonFieldType.STRING).description("쿠폰 사용 가능 요일").optional(), fieldWithPath("exposure_start_date").type(JsonFieldType.STRING).description("노출 시작 날짜"), fieldWithPath("exposure_end_date").type(JsonFieldType.STRING).description("노출 종료 날짜"), @@ -400,7 +402,8 @@ void updateCoupon_success() throws Exception { coupon.getCouponRooms().isEmpty(), coupon.getCouponRooms().stream().map(room -> room.getRoom().getRoomNumber()).toList(), coupon.getMinimumReservationPrice() + 10000, - DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays()).getValue(), + Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays())) + .map(DtoCouponUseDaysType::getValue).orElse(null), Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDayOfWeek(coupon.getCouponUseDays())) .map(DtoCouponUseDayOfWeekType::getValue).orElse(null), coupon.getExposureStartDate(), diff --git a/src/test/java/com/coolpeace/domain/coupon/service/CouponServiceTest.java b/src/test/java/com/coolpeace/domain/coupon/service/CouponServiceTest.java index 8d42912..5565ac9 100644 --- a/src/test/java/com/coolpeace/domain/coupon/service/CouponServiceTest.java +++ b/src/test/java/com/coolpeace/domain/coupon/service/CouponServiceTest.java @@ -9,6 +9,7 @@ import com.coolpeace.domain.coupon.dto.request.CouponUpdateRequest; import com.coolpeace.domain.coupon.dto.request.SearchCouponParams; import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDayOfWeekType; +import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType; import com.coolpeace.domain.coupon.dto.request.type.SearchCouponDateFilterType; import com.coolpeace.domain.coupon.dto.request.type.SearchCouponStatusFilterType; import com.coolpeace.domain.coupon.dto.response.CouponResponse; @@ -328,7 +329,8 @@ private CouponRegisterRequest getCouponRegisterRequest(boolean registerAllRoom) registerAllRoom, !registerAllRoom ? registerRoomNumbers : null, coupon.getMinimumReservationPrice(), - DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays()).getValue(), + Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays())) + .map(DtoCouponUseDaysType::getValue).orElse(null), Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDayOfWeek(coupon.getCouponUseDays())) .map(DtoCouponUseDayOfWeekType::getValue).orElse(null), coupon.getExposureStartDate(), @@ -400,7 +402,8 @@ void updateCoupon_mono_update_success() { null, null, couponB.getMinimumReservationPrice(), - DtoCouponUtil.filteringCouponUseConditionDays(couponB.getCouponUseDays()).getValue(), + Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDays(couponB.getCouponUseDays())) + .map(DtoCouponUseDaysType::getValue).orElse(null), Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDayOfWeek(couponB.getCouponUseDays())) .map(DtoCouponUseDayOfWeekType::getValue).orElse(null), couponB.getExposureStartDate(),