-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from CoolPeace-yanolza/feature/coupon/register
쿠폰 할인 유형 관련 싱크업
- Loading branch information
Showing
11 changed files
with
121 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/coolpeace/domain/coupon/dto/request/validator/CouponRequestValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.coolpeace.domain.coupon.dto.request.validator; | ||
|
||
import com.coolpeace.domain.coupon.entity.type.DiscountType; | ||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.ValidationUtils; | ||
import org.springframework.validation.Validator; | ||
|
||
public abstract class CouponRequestValidator implements Validator { | ||
|
||
// 방 등록 유효성 검사 | ||
protected static void validateRegisterRooms(Errors errors, boolean registerAllRoom) { | ||
if (!registerAllRoom) { | ||
ValidationUtils.rejectIfEmpty(errors, | ||
"registerRooms", | ||
"registerRooms.empty", | ||
"등록할 객실을 선택해주세요."); | ||
} | ||
} | ||
|
||
// 할인 유형 유효성 검사 | ||
protected static void validateDiscountValues(Errors errors, | ||
String requestedDiscountTypeStr, | ||
Integer requestedDiscountFlatValue, | ||
Integer requestedDiscountFlatRate) { | ||
if (requestedDiscountTypeStr.equals(DiscountType.FIXED_PRICE.getValue())) { | ||
if (requestedDiscountFlatValue == null || requestedDiscountFlatValue <= 0) { | ||
errors.reject("discountFlatValue.empty", "정액 할인의 경우 할인 금액를 입력해야 합니다."); | ||
} | ||
} else { | ||
if (requestedDiscountFlatRate == null || requestedDiscountFlatRate <= 0) { | ||
errors.reject("discountFlatValue.empty", "정률 할인의 경우 할인 비율을 입력해야 합니다."); | ||
} | ||
} | ||
} | ||
} |
31 changes: 4 additions & 27 deletions
31
.../java/com/coolpeace/domain/coupon/dto/request/validator/CouponUpdateRequestValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,21 @@ | ||
package com.coolpeace.domain.coupon.dto.request.validator; | ||
|
||
import com.coolpeace.domain.coupon.dto.request.CouponRegisterRequest; | ||
import com.coolpeace.domain.coupon.dto.request.CouponUpdateRequest; | ||
import com.coolpeace.domain.coupon.entity.type.DiscountType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.CollectionUtils; | ||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.Validator; | ||
|
||
@Component | ||
public class CouponUpdateRequestValidator implements Validator { | ||
public class CouponUpdateRequestValidator extends CouponRequestValidator { | ||
@Override | ||
public boolean supports(Class<?> clazz) { | ||
return CouponUpdateRequest.class.equals(clazz); | ||
} | ||
|
||
@Override | ||
public void validate(Object target, Errors errors) { | ||
CouponRegisterRequest request = (CouponRegisterRequest) target; | ||
|
||
// 할인 유형 | ||
if (request.discountType().equals(DiscountType.FIXED_PRICE.getValue())) { | ||
if (request.discountValue() < 100) { | ||
errors.reject("discountValue", | ||
"정액 할인일 경우 값을 100 이상으로 설정해야 합니다."); | ||
} | ||
} else { | ||
if (request.discountValue() > 100) { | ||
errors.reject("discountValue", | ||
"정률 할인일 경우 값을 100 이하로 설정해야 합니다."); | ||
} | ||
} | ||
|
||
// 특정 객실 등록 | ||
if (!request.registerAllRoom()) { | ||
if (CollectionUtils.isEmpty(request.registerRooms())) { | ||
errors.reject("registerRooms.empty", | ||
"등록할 객실 리스트가 비어 있습니다."); | ||
} | ||
} | ||
CouponUpdateRequest request = (CouponUpdateRequest) target; | ||
|
||
validateRegisterRooms(errors, request.registerAllRoom()); | ||
validateDiscountValues(errors, request.discountType(), request.discountFlatValue(), request.discountFlatRate()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.