Skip to content

Commit

Permalink
[TDC-140] Coupon time 로 변경
Browse files Browse the repository at this point in the history
[TDC-140] 일단 유니크 키 제거
  • Loading branch information
yerimkoko committed Jan 7, 2025
1 parent 06b5f8c commit a76854a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@

import com.threedollar.domain.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

import java.time.LocalDateTime;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.checkerframework.checker.units.qual.C;

@Entity
@Getter
@NoArgsConstructor
@Table(uniqueConstraints = {
@UniqueConstraint(
name = "uni_coupon_1",
columnNames = {}
)
})
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Coupon extends BaseEntity {

@Column(nullable = false, length = 100)
Expand All @@ -51,43 +43,38 @@ public class Coupon extends BaseEntity {
@Column(nullable = false)
private long count;

@Column(nullable = false)
private LocalDateTime startTime;

@Column(nullable = false)
private LocalDateTime endTime;
@Embedded
private CouponTime couponTime;

@Column(nullable = false)
private String accountId;

@Builder(access = AccessLevel.PRIVATE)
public Coupon(String workspaceId, String targetId, String name, CouponType couponType,
CouponTag couponTag, CouponStatus status, long count, LocalDateTime startTime, LocalDateTime endTime,
String accountId) {
CouponTag couponTag, CouponStatus status, CouponTime couponTime, long count, String accountId) {
this.workspaceId = workspaceId;
this.targetId = targetId;
this.name = name;
this.couponTag = couponTag;
this.couponType = couponType;
this.status = status;
this.count = count;
this.startTime = startTime;
this.endTime = endTime;
this.couponTime = couponTime;
this.accountId = accountId;
}

public static Coupon newInstance(String workspaceId, String targetId, String name,
CouponType couponType, CouponTag couponTag, long count, LocalDateTime startTime, LocalDateTime endTime) {
CouponType couponType, CouponTag couponTag, long count, CouponTime couponTime, String accountId) {
return Coupon.builder()
.couponType(couponType)
.workspaceId(workspaceId)
.targetId(targetId)
.name(name)
.couponTag(couponTag)
.couponTime(couponTime)
.accountId(accountId)
.count(count)
.status(CouponStatus.ACTIVE)
.startTime(startTime)
.endTime(endTime)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.threedollar.domain.coupon;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

import java.time.LocalDateTime;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@NoArgsConstructor
@Getter
public class CouponTime {

@Column(nullable = false)
private LocalDateTime startTime;

@Column(nullable = false)
private LocalDateTime endTime;

public CouponTime(LocalDateTime startTime, LocalDateTime endTime) {
validateCouponTime(startTime, endTime);
this.startTime = startTime;
this.endTime = endTime;
}

private void validateCouponTime(LocalDateTime startTime, LocalDateTime endTime) {
if (startTime.isAfter(endTime)) {
throw new IllegalArgumentException("startTime is after endTime");
}
}
}

0 comments on commit a76854a

Please sign in to comment.