-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: 무료 주문 생성하기 API 구현 #520
Changes from 14 commits
9cb0bb1
409b6df
023843f
1142a54
86584b7
3c5fa21
ba6ff1d
ce6ee9c
df2936e
f7e88f4
c3005dd
34edf71
80e4447
9da42f9
58e61de
b25c3f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,26 @@ public static Order createPending( | |
.build(); | ||
} | ||
|
||
public static Order createFree( | ||
String nanoId, Membership membership, @Nullable IssuedCoupon issuedCoupon, MoneyInfo moneyInfo) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 무료 주문이면 쿠폰이 반드시 필요한거아닌가요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 회비가 0원인 경우에는 쿠폰 없이 무료 주문이 가능하다고 봤어요 |
||
validateFreeOrder(moneyInfo); | ||
return Order.builder() | ||
.status(OrderStatus.COMPLETED) | ||
.nanoId(nanoId) | ||
.memberId(membership.getMember().getId()) | ||
.membershipId(membership.getId()) | ||
.recruitmentRoundId(membership.getRecruitmentRound().getId()) | ||
.issuedCouponId(issuedCoupon != null ? issuedCoupon.getId() : null) | ||
.moneyInfo(moneyInfo) | ||
.build(); | ||
} | ||
|
||
private static void validateFreeOrder(MoneyInfo moneyInfo) { | ||
if (!moneyInfo.isFree()) { | ||
throw new CustomException(ORDER_FREE_FINAL_PAYMENT_NOT_ZERO); | ||
} | ||
} | ||
|
||
// 데이터 변경 로직 | ||
|
||
/** | ||
|
@@ -119,6 +139,7 @@ public void complete(String paymentKey, ZonedDateTime approvedAt) { | |
* 상태 변경 및 취소 시각을 저장하며, 예외를 발생시키지 않도록 외부 취소 요청 전에 validateCancelable을 호출합니다. | ||
*/ | ||
public void cancel(ZonedDateTime canceledAt) { | ||
// TODO: 취소 이벤트 발행을 통해 멤버십 및 멤버 상태에 대한 변경 로직 추가 | ||
validateCancelable(); | ||
this.status = OrderStatus.CANCELED; | ||
this.canceledAt = canceledAt; | ||
|
@@ -128,11 +149,19 @@ public void validateCancelable() { | |
if (status != OrderStatus.COMPLETED) { | ||
throw new CustomException(ORDER_CANCEL_NOT_COMPLETED); | ||
} | ||
|
||
if (isFree()) { | ||
throw new CustomException(ORDER_CANCEL_FREE_ORDER); | ||
} | ||
} | ||
|
||
// 데이터 조회 로직 | ||
|
||
public boolean isCompleted() { | ||
return status == OrderStatus.COMPLETED; | ||
} | ||
|
||
public boolean isFree() { | ||
return moneyInfo.isFree(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.