forked from Eunnee/popool
-
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.
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
Payment-Service/src/main/java/kr/co/paymentservice/domain/entity/InventoryEntity.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,76 @@ | ||
package kr.co.paymentservice.domain.entity; | ||
|
||
import kr.co.paymentservice.domain.shared.BaseEntity; | ||
import kr.co.paymentservice.domain.shared.enums.CouponPeriod; | ||
import lombok.Getter; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Table(name = "tbl_inventory") | ||
@Entity | ||
public class InventoryEntity extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "inventory_id") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long memberId; //기업 회원과 일대일 관계 | ||
|
||
@Column(nullable = false) | ||
private int remainCouponCnt; | ||
|
||
@Column(nullable = false) | ||
private LocalDate endPeriodDate; | ||
|
||
@Column(nullable = false) | ||
private boolean isSubscription; | ||
|
||
|
||
//== coupon ==// | ||
public void useRemainCoupon(int usedCouponNum) { | ||
if (this.remainCouponCnt - usedCouponNum < 0) | ||
throw new RuntimeException("쿠폰이 충분하지 않습니다."); | ||
|
||
this.remainCouponCnt -= usedCouponNum; | ||
} | ||
|
||
public void addCoupon(int addCouponNum) { | ||
this.remainCouponCnt += addCouponNum; | ||
} | ||
|
||
|
||
//== period ==// | ||
public boolean isPeriodValid() { | ||
if (endPeriodDate.isAfter(LocalDate.now()) || endPeriodDate.isEqual(LocalDate.now())) | ||
return true; | ||
return false; | ||
} | ||
|
||
public void addPeriod(CouponPeriod couponPeriod) { | ||
if (isPeriodValid()) { | ||
this.endPeriodDate = this.endPeriodDate.plusMonths(couponPeriod.getPeriod()); | ||
} | ||
else { | ||
this.endPeriodDate = LocalDate.now().plusMonths(couponPeriod.getPeriod()); | ||
} | ||
} | ||
|
||
//== subscription ==// | ||
public void doSubscription() { | ||
if (this.isSubscription) | ||
throw new RuntimeException("이미 구독중입니다."); | ||
|
||
if (isPeriodValid()) | ||
throw new RuntimeException("기간권 사용중입니다."); | ||
|
||
this.isSubscription = true; | ||
} | ||
|
||
public void cancelSubscription() { | ||
this.isSubscription = false; | ||
} | ||
} |