345d4c056c
Release package / release (push) Successful in 26m36s
Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Reviewed-on: #51
68 lines
1.4 KiB
Java
68 lines
1.4 KiB
Java
package com.drinkool.entities;
|
|
|
|
import com.drinkool.lib.entities.BaseEntity;
|
|
import jakarta.persistence.*;
|
|
import jakarta.transaction.Transactional;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
@Entity
|
|
@Table
|
|
public class EateryEntity extends BaseEntity {
|
|
|
|
@Column(unique = true, nullable = false)
|
|
public UUID ownerId;
|
|
|
|
@Column(unique = true, nullable = false)
|
|
public String name;
|
|
|
|
@Column(nullable = false)
|
|
public boolean isVerified = false;
|
|
|
|
@OneToMany(
|
|
mappedBy = "eatery",
|
|
cascade = CascadeType.ALL,
|
|
orphanRemoval = true
|
|
)
|
|
public List<MenuItemEntity> menuItems = new ArrayList<>();
|
|
|
|
@OneToMany(
|
|
mappedBy = "eatery",
|
|
cascade = CascadeType.ALL,
|
|
orphanRemoval = true
|
|
)
|
|
public List<ShiftEntity> shifts = new ArrayList<>();
|
|
|
|
public EateryEntity() {}
|
|
|
|
@Transactional
|
|
public EateryEntity create(UUID ownerId, String name) {
|
|
EateryEntity existedEatery = EateryEntity.find(
|
|
"ownerId",
|
|
ownerId
|
|
).firstResult();
|
|
|
|
if (existedEatery != null) throw new RuntimeException("ExistedEatery");
|
|
|
|
this.ownerId = ownerId;
|
|
this.name = name;
|
|
|
|
this.persist();
|
|
|
|
return this;
|
|
}
|
|
|
|
@Transactional
|
|
public static EateryEntity findByOwnerId(String ownerId) {
|
|
UUID ownerUUID = UUID.fromString(ownerId);
|
|
|
|
return EateryEntity.find("ownerId", ownerUUID).firstResult();
|
|
}
|
|
|
|
@Transactional
|
|
public static EateryEntity findByOwnerId(UUID ownerId) {
|
|
return EateryEntity.find("ownerId", ownerId).firstResult();
|
|
}
|
|
}
|