55 lines
1.3 KiB
Java
55 lines
1.3 KiB
Java
package com.krylov.refound.entity.advertising;
|
|
|
|
import com.krylov.refound.enums.advertising.CampaignStatus;
|
|
import com.krylov.refound.util.TimeZoneContext;
|
|
import jakarta.persistence.*;
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Entity
|
|
@Table(name = "campaign")
|
|
@Getter
|
|
@Setter
|
|
public class Campaign {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(nullable = false, length = 255)
|
|
private String name;
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
@Column(nullable = false, length = 20)
|
|
private CampaignStatus status = CampaignStatus.PAUSED;
|
|
|
|
@Column(name = "start_date", nullable = false)
|
|
private LocalDateTime startDate;
|
|
|
|
@Column(name = "end_date", nullable = false)
|
|
private LocalDateTime endDate;
|
|
|
|
@Column(name = "daily_impression_cap", nullable = false)
|
|
private Integer dailyImpressionCap = 10;
|
|
|
|
@Column(name = "created_at", nullable = false)
|
|
private LocalDateTime createdAt;
|
|
|
|
@OneToMany(
|
|
mappedBy = "campaign",
|
|
cascade = CascadeType.ALL,
|
|
orphanRemoval = true
|
|
)
|
|
private List<Advertising> ads = new ArrayList<>();
|
|
|
|
@PrePersist
|
|
protected void onCreate() {
|
|
if (createdAt == null) {
|
|
createdAt = TimeZoneContext.now();
|
|
}
|
|
}
|
|
} |