From 05824aa5749fe40e3a50c8f68068a352035b17d3 Mon Sep 17 00:00:00 2001 From: sochong Date: Sat, 2 Jul 2022 02:48:11 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20Inventory=20Entity=20=EC=84=A4=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/InventoryEntity.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Payment-Service/src/main/java/kr/co/paymentservice/domain/entity/InventoryEntity.java diff --git a/Payment-Service/src/main/java/kr/co/paymentservice/domain/entity/InventoryEntity.java b/Payment-Service/src/main/java/kr/co/paymentservice/domain/entity/InventoryEntity.java new file mode 100644 index 0000000..aff4131 --- /dev/null +++ b/Payment-Service/src/main/java/kr/co/paymentservice/domain/entity/InventoryEntity.java @@ -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; + } +}