-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0061aad
commit f0c4867
Showing
10 changed files
with
197 additions
and
67 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
34 changes: 25 additions & 9 deletions
34
src/main/java/com/hcommerce/heecommerce/order/OrderForm.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,23 +1,39 @@ | ||
package com.hcommerce.heecommerce.order; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.beans.ConstructorProperties; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class OrderForm { | ||
|
||
private OrdererInfo ordererInfo; | ||
private RecipientInfo recipientInfo; | ||
private PaymentInfo paymentInfo; | ||
@Valid | ||
@NotNull(message = "주문자 정보는 필수입니다.") | ||
private OrdererInfoForm ordererInfoForm; | ||
|
||
@Valid | ||
@NotNull(message = "수령자 정보는 필수입니다.") | ||
private RecipientInfoForm recipientInfoForm; | ||
|
||
@Valid | ||
@NotNull(message = "결제 정보는 필수입니다.") | ||
private PaymentInfoForm paymentInfoForm; | ||
|
||
@Builder | ||
@ConstructorProperties({ | ||
"ordererInfoForm", | ||
"recipientInfoForm", | ||
"paymentInfoForm"} | ||
) | ||
public OrderForm( | ||
OrdererInfo ordererInfo, | ||
RecipientInfo recipientInfo, | ||
PaymentInfo paymentInfo | ||
OrdererInfoForm ordererInfoForm, | ||
RecipientInfoForm recipientInfoForm, | ||
PaymentInfoForm paymentInfoForm | ||
) { | ||
this.ordererInfo = ordererInfo; | ||
this.recipientInfo = recipientInfo; | ||
this.paymentInfo = paymentInfo; | ||
this.ordererInfoForm = ordererInfoForm; | ||
this.recipientInfoForm = recipientInfoForm; | ||
this.paymentInfoForm = paymentInfoForm; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/hcommerce/heecommerce/order/OrderFormValidator.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,43 @@ | ||
package com.hcommerce.heecommerce.order; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.Validator; | ||
|
||
@Component | ||
public class OrderFormValidator implements Validator { | ||
|
||
@Override | ||
public boolean supports(Class<?> clazz) { | ||
return OrderForm.class.equals(clazz); | ||
} | ||
|
||
@Override | ||
public void validate(Object target, Errors errors) { | ||
OrderForm orderForm = (OrderForm) target; | ||
|
||
if(orderForm.getPaymentInfoForm() != null) { | ||
validatePaymentInfoForm(orderForm.getPaymentInfoForm(), errors); | ||
} | ||
} | ||
|
||
private void validatePaymentInfoForm(PaymentInfoForm paymentInfoForm, Errors errors) { | ||
|
||
if (paymentInfoForm.getDiscountAmount() > paymentInfoForm.getOriginPrice()) { | ||
errors.rejectValue("paymentInfoForm.totalDiscountAmount", "paymentInfoForm.discountAmount.invalid", "할인 금액은 상품 가격을 초과할 수 없습니다."); | ||
return; | ||
} | ||
|
||
if (paymentInfoForm.getTotalDiscountAmount() > paymentInfoForm.getTotalDealProductAmount()) { | ||
errors.rejectValue("paymentInfoForm.totalDiscountAmount", "paymentInfoForm.discountAmount.invalid", "총 할인 금액은 총 상품 가격을 초과할 수 없습니다."); | ||
return; | ||
} | ||
|
||
int MAX_ORDER_QUANTITY_PER_ORDER = 10; // TODO: 딜 상품마다 최대 주문량을 다른 값을 갖도록 상황을 가정했으므로, DB에서 가져올 예정 | ||
// (참고: https://github.com/f-lab-edu/home-delivery/blob/b78ba80d38dd6e1e59554ebea59343a52d770e1d/src/main/java/com/flab/delivery/controller/validator/OrderValidator.java#L1) | ||
|
||
if (paymentInfoForm.getOrderQuantity() > MAX_ORDER_QUANTITY_PER_ORDER) { | ||
errors.rejectValue("paymentInfoForm.orderQuantity", "paymentInfoForm.orderQuantity.invalid", "최대 주문 수량은 " + MAX_ORDER_QUANTITY_PER_ORDER + "개 입니다."); | ||
} | ||
} | ||
} |
12 changes: 10 additions & 2 deletions
12
...mmerce/heecommerce/order/OrdererInfo.java → ...ce/heecommerce/order/OrdererInfoForm.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
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.