-
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
7676d9e
commit abbf282
Showing
12 changed files
with
210 additions
and
248 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
49 changes: 36 additions & 13 deletions
49
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,29 +1,52 @@ | ||
package com.hcommerce.heecommerce.order; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.beans.ConstructorProperties; | ||
import java.util.UUID; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.hibernate.validator.constraints.Range; | ||
|
||
@Getter | ||
public class OrderForm { | ||
|
||
private OrdererInfo ordererInfo; | ||
private RecipientInfo recipientInfo; | ||
private PaymentInfo paymentInfo; | ||
@Range(min = 1, message = "주문자 ID를 확인해주세요.") | ||
private final int userId; | ||
|
||
@Valid | ||
@NotNull(message = "수령자 정보는 필수입니다.") | ||
private RecipientInfoForm recipientInfoForm; | ||
|
||
@NotNull(message = "딜 상품 UUID를 입력해주세요.") | ||
private final UUID dealProductUuid; | ||
|
||
@Min(value = 1, message = "주문 수량은 1개 이상이어야 합니다.") | ||
private final int orderQuantity; | ||
|
||
@NotNull(message = "결제 유형을 입력해주세요.") | ||
private final PaymentType paymentType; | ||
|
||
@Builder | ||
@ConstructorProperties({ | ||
"ordererInfo", | ||
"recipientInfo", | ||
"paymentInfo"} | ||
) | ||
"userId", | ||
"recipientInfoForm", | ||
"dealProductUuid", | ||
"orderQuantity", | ||
"paymentType" | ||
}) | ||
public OrderForm( | ||
OrdererInfo ordererInfo, | ||
RecipientInfo recipientInfo, | ||
PaymentInfo paymentInfo | ||
int userId, | ||
RecipientInfoForm recipientInfoForm, | ||
UUID dealProductUuid, | ||
int orderQuantity, | ||
PaymentType paymentType | ||
) { | ||
this.ordererInfo = ordererInfo; | ||
this.recipientInfo = recipientInfo; | ||
this.paymentInfo = paymentInfo; | ||
this.userId = userId; | ||
this.recipientInfoForm = recipientInfoForm; | ||
this.dealProductUuid = dealProductUuid; | ||
this.orderQuantity = orderQuantity; | ||
this.paymentType = paymentType; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
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; | ||
|
||
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 (orderForm.getOrderQuantity() > MAX_ORDER_QUANTITY_PER_ORDER) { | ||
errors.rejectValue("orderQuantity", "orderQuantity.invalid", "최대 주문 수량은 " + MAX_ORDER_QUANTITY_PER_ORDER + "개 입니다."); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/com/hcommerce/heecommerce/order/OrdererInfo.java
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
src/main/java/com/hcommerce/heecommerce/order/PaymentInfo.java
This file was deleted.
Oops, something went wrong.
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.