Skip to content

Commit

Permalink
Feat: Inventory Entity 설계
Browse files Browse the repository at this point in the history
  • Loading branch information
hsju0202 committed Jul 1, 2022
1 parent 7856716 commit 05824aa
Showing 1 changed file with 76 additions and 0 deletions.
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;
}
}

0 comments on commit 05824aa

Please sign in to comment.