feat: add zoo sample
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
@Table(name = "tb_zoo")
|
||||
public class ZooEntity extends CommonDateEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long uid;
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
private UUID uuid;
|
||||
|
||||
@Column(nullable = false, length = 200)
|
||||
private String name;
|
||||
|
||||
@Column(length = 300)
|
||||
private String location;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String description;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Boolean isDeleted;
|
||||
|
||||
@OneToMany(mappedBy = "zoo", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
private List<AnimalEntity> animals = new ArrayList<>();
|
||||
|
||||
// Constructor
|
||||
public ZooEntity(String name, String location, String description) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.description = description;
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
// 논리 삭제
|
||||
public void deleted() {
|
||||
this.isDeleted = true;
|
||||
}
|
||||
|
||||
// 현재 활성 동물 개수 조회 (삭제되지 않은 동물만)
|
||||
public long getActiveAnimalCount() {
|
||||
return animals.stream().filter(animal -> !animal.getIsDeleted()).count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user