Skip to content

Commit

Permalink
Merge pull request #214 from CoolPeace-yanolza/feature/coupon/conditi…
Browse files Browse the repository at this point in the history
…onal

쿠폰 도메인 관련 싱크업
  • Loading branch information
tkddn204 authored Jan 27, 2024
2 parents 902eab4 + 8e17978 commit 22571aa
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class Coupon extends BaseTimeEntity {
private final List<DayOfWeek> couponUseConditionDays = Collections.emptyList();

@Enumerated(EnumType.STRING)
private CouponUseDaysType couponUseDays = CouponUseDaysType.WEEKEND;
private CouponUseDaysType couponUseDays = CouponUseDaysType.ALL;

@Column(nullable = false)
private LocalDate exposureStartDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
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;
import org.springframework.data.domain.Sort;
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;
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 13 additions & 10 deletions src/test/java/com/coolpeace/docs/coupon/CouponControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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("노출 종료 날짜")
Expand Down Expand Up @@ -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("노출 종료 날짜"),
Expand Down Expand Up @@ -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("노출 종료 날짜"),
Expand Down Expand Up @@ -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("노출 종료 날짜"),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 22571aa

Please sign in to comment.