Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

쿠폰 등록, 수정, 조회 시 요청 응답 싱크업 #202

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/com/coolpeace/domain/coupon/dto/DtoCouponUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.coolpeace.domain.coupon.dto;

import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDayOfWeekType;
import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType;
import com.coolpeace.domain.coupon.entity.type.CouponUseDaysType;
public class DtoCouponUtil {

public static DtoCouponUseDaysType filteringCouponUseConditionDays(CouponUseDaysType couponUseDays) {
if (couponUseDays.isOneDay()) {
return DtoCouponUseDaysType.ONEDAY;
}
return DtoCouponUseDaysType.valueOf(couponUseDays.name());
}

public static DtoCouponUseDayOfWeekType filteringCouponUseConditionDayOfWeek(CouponUseDaysType couponUseDays) {
if (couponUseDays.isOneDay()) {
return DtoCouponUseDayOfWeekType.valueOf(couponUseDays.name());
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coolpeace.domain.coupon.dto.request;

import com.coolpeace.domain.coupon.entity.type.CouponUseDaysType;
import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDayOfWeekType;
import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType;
import com.coolpeace.domain.coupon.entity.type.CustomerType;
import com.coolpeace.domain.coupon.entity.type.DiscountType;
import com.coolpeace.global.common.validator.ValidEnum;
Expand All @@ -16,6 +17,7 @@ public record CouponRegisterRequest(
@NotBlank(message = "쿠폰의 이름을 입력해야 합니다.")
@Size(max = 20, message = "쿠폰의 이름은 20자 내외로 입력해야 합니다.")
String title,

@NotNull(message = "고객의 유형을 선택해야 합니다.")
@ValidEnum(enumClass = CustomerType.class, message = "올바르지 않은 고객의 유형입니다.")
String customerType,
Expand All @@ -30,7 +32,6 @@ public record CouponRegisterRequest(

// 객실 유형
List<String> couponRoomTypes,
Boolean couponRoomStayMore,

// 숙소 ID
@NotNull(message = "숙박업체의 ID를 입력해야 합니다.")
Expand All @@ -43,8 +44,10 @@ public record CouponRegisterRequest(

// 쿠폰 사용 조건
Integer minimumReservationPrice,
@ValidEnum(enumClass = CouponUseDaysType.class, message = "올바르지 않은 사용 조건의 날짜 유형입니다.", required = false)
@ValidEnum(enumClass = DtoCouponUseDaysType.class, message = "올바르지 않은 사용 조건의 날짜 유형입니다.")
String couponUseConditionDays,
@ValidEnum(enumClass = DtoCouponUseDayOfWeekType.class, message = "올바르지 않은 사용 조건의 요일입니다.", required = false)
String couponUseConditionDayOfWeek,

// 노출 날짜
@NotNull(message = "노출 시작 날짜를 입력해야 합니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coolpeace.domain.coupon.dto.request;

import com.coolpeace.domain.coupon.entity.type.CouponUseDaysType;
import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDayOfWeekType;
import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType;
import com.coolpeace.domain.coupon.entity.type.CustomerType;
import com.coolpeace.domain.coupon.entity.type.DiscountType;
import com.coolpeace.global.common.validator.ValidEnum;
Expand All @@ -22,12 +23,13 @@ public record CouponUpdateRequest(
Integer discountFlatRate,
Integer maximumDiscountPrice,
List<String> couponRoomTypes,
Boolean couponRoomStayMore,
Boolean registerAllRoom,
List<String> registerRooms,
Integer minimumReservationPrice,
@ValidEnum(enumClass = CouponUseDaysType.class, message = "올바르지 않은 사용 조건의 날짜 유형입니다.", required = false)
@ValidEnum(enumClass = DtoCouponUseDaysType.class, message = "올바르지 않은 사용 조건의 날짜 유형입니다.", required = false)
String couponUseConditionDays,
@ValidEnum(enumClass = DtoCouponUseDayOfWeekType.class, message = "올바르지 않은 사용 조건의 요일입니다.", required = false)
String couponUseConditionDayOfWeek,
@JsonFormat(pattern = "yyyy-MM-dd")
LocalDate exposureStartDate,
@JsonFormat(pattern = "yyyy-MM-dd")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.coolpeace.domain.coupon.dto.request.type;

import com.coolpeace.global.common.ValuedEnum;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum DtoCouponUseDayOfWeekType implements ValuedEnum {
MONDAY("월요일"),
TUESDAY("화요일"),
WEDNESDAY("수요일"),
THURSDAY("목요일"),
FRIDAY("금요일"),
SATURDAY("토요일"),
SUNDAY("일요일");

private final String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.coolpeace.domain.coupon.dto.request.type;

import com.coolpeace.global.common.ValuedEnum;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum DtoCouponUseDaysType implements ValuedEnum {
ONEDAY("하루만"),
WEEKDAY("평일"),
WEEKEND("주말");

private final String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public void validate(Object target, Errors errors) {
validateRegisterRooms(errors, request.registerAllRoom());
validateDiscountValues(errors, request.discountType(), request.discountFlatValue(), request.discountFlatRate());
validateCouponRoomTypes(errors, request.couponRoomTypes());
validateCouponRoomConditionDays(errors, request.couponUseConditionDays());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coolpeace.domain.coupon.dto.request.validator;

import com.coolpeace.domain.coupon.dto.request.type.DtoCouponUseDaysType;
import com.coolpeace.domain.coupon.entity.type.CouponRoomType;
import com.coolpeace.domain.coupon.entity.type.DiscountType;
import com.coolpeace.global.common.ValuedEnum;
Expand Down Expand Up @@ -54,4 +55,14 @@ protected static void validateCouponRoomTypes(Errors errors, List<String> coupon
}
}
}

protected static void validateCouponRoomConditionDays(Errors errors,
String couponUseConditionDays) {
if (ValuedEnum.of(DtoCouponUseDaysType.class, couponUseConditionDays).equals(DtoCouponUseDaysType.ONEDAY)) {
ValidationUtils.rejectIfEmpty(errors,
"couponUseConditionDayOfWeek",
"couponUseConditionDayOfWeek.empty",
"사용 조건의 요일을 선택해야 합니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public void validate(Object target, Errors errors) {
validateRegisterRooms(errors, request.registerAllRoom());
validateDiscountValues(errors, request.discountType(), request.discountFlatValue(), request.discountFlatRate());
validateCouponRoomTypes(errors, request.couponRoomTypes());
validateCouponRoomConditionDays(errors, request.couponUseConditionDays());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.coolpeace.domain.coupon.dto.response;

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.entity.Coupon;
import com.coolpeace.domain.coupon.entity.type.CouponRoomType;
import com.coolpeace.domain.coupon.entity.type.DiscountType;

import java.time.LocalDate;
Expand All @@ -20,9 +21,9 @@ public record CouponResponse(
Integer maximumDiscountPrice,
String customerType,
List<String> couponRoomTypes,
Boolean couponRoomStayMore,
Integer minimumReservationPrice,
String couponUseConditionDays,
String couponUseConditionDayOfWeek,
LocalDate exposureStartDate,
LocalDate exposureEndDate,
Integer couponExpiration,
Expand All @@ -44,10 +45,11 @@ public static CouponResponse from(Coupon coupon) {
coupon.getDiscountType().equals(DiscountType.FIXED_RATE) ? coupon.getDiscountValue() : null,
coupon.getMaximumDiscountPrice(),
coupon.getCustomerType().getValue(),
coupon.getCouponRoomTypeStringsExcludingTwoNight(),
coupon.getCouponRoomStayType() != null && coupon.getCouponRoomStayType().equals(CouponRoomType.TWO_NIGHT),
coupon.getCouponRoomTypeStrings(),
coupon.getMinimumReservationPrice(),
coupon.getCouponUseDays().getValue(),
DtoCouponUtil.filteringCouponUseConditionDays(coupon.getCouponUseDays()).getValue(),
Optional.ofNullable(DtoCouponUtil.filteringCouponUseConditionDayOfWeek(coupon.getCouponUseDays()))
.map(DtoCouponUseDayOfWeekType::getValue).orElse(null),
coupon.getExposureStartDate(),
coupon.getExposureEndDate(),
coupon.getCouponExpiration(),
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java
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.ALL;
private CouponUseDaysType couponUseDays = CouponUseDaysType.WEEKEND;

@Column(nullable = false)
private LocalDate exposureStartDate;
Expand Down Expand Up @@ -155,11 +155,16 @@ public static Coupon from(
);
}

public List<String> getCouponRoomTypeStringsExcludingTwoNight() {
public List<String> getCouponRoomTypeStrings() {
return Stream.of(this.getCouponRoomType(), this.getCouponRoomStayType())
.filter(Objects::nonNull)
.map(roomType -> (roomType == CouponRoomType.TWO_NIGHT) ? CouponRoomType.LODGE : roomType)
.map(CouponRoomType::getValue).toList();
.flatMap(roomType -> {
if (roomType.equals(CouponRoomType.TWO_NIGHT)) {
return Stream.of(CouponRoomType.LODGE.getValue(), CouponRoomType.TWO_NIGHT.getValue());
} else {
return Stream.of(roomType.getValue());
}
}).toList();
}

public String getCouponTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public enum CouponUseDaysType implements ValuedEnum {
SATURDAY("토"),
SUNDAY("일"),
WEEKDAY("평일"),
WEEKEND("주말"),
ALL("전체");
WEEKEND("주말");

private final String value;

public boolean isOneDay() {
return !this.equals(WEEKDAY) && !this.equals(WEEKEND);
}
}
Loading
Loading