84 lines
2.1 KiB
Java
84 lines
2.1 KiB
Java
package app.mealsmadeeasy.api.recipe;
|
|
|
|
import app.mealsmadeeasy.api.image.Image;
|
|
import app.mealsmadeeasy.api.recipe.comment.RecipeComment;
|
|
import app.mealsmadeeasy.api.recipe.star.RecipeStar;
|
|
import app.mealsmadeeasy.api.user.User;
|
|
import jakarta.persistence.*;
|
|
import lombok.Data;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.time.OffsetDateTime;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
@Entity(name = "Recipe")
|
|
@Data
|
|
public final class Recipe {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
@Column(nullable = false, updatable = false)
|
|
private Integer id;
|
|
|
|
@Column(nullable = false)
|
|
private OffsetDateTime created;
|
|
|
|
private OffsetDateTime modified;
|
|
|
|
@Column(nullable = false, unique = true)
|
|
private String slug;
|
|
|
|
@Column(nullable = false)
|
|
private String title;
|
|
|
|
@Nullable
|
|
private Integer preparationTime;
|
|
|
|
@Nullable
|
|
private Integer cookingTime;
|
|
|
|
@Nullable
|
|
private Integer totalTime;
|
|
|
|
@Lob
|
|
@Column(name = "raw_text", columnDefinition = "TEXT", nullable = false)
|
|
@Basic(fetch = FetchType.LAZY)
|
|
private String rawText;
|
|
|
|
@Lob
|
|
@Column(name = "cached_rendered_text", columnDefinition = "TEXT")
|
|
@Basic(fetch = FetchType.LAZY)
|
|
private String cachedRenderedText;
|
|
|
|
@ManyToOne(optional = false)
|
|
@JoinColumn(name = "owner_id", nullable = false)
|
|
private User owner;
|
|
|
|
@OneToMany
|
|
@JoinColumn(name = "recipe_id")
|
|
private Set<RecipeStar> stars = new HashSet<>();
|
|
|
|
@OneToMany(mappedBy = "recipe")
|
|
private Set<RecipeComment> comments = new HashSet<>();
|
|
|
|
@Column(nullable = false)
|
|
private Boolean isPublic = false;
|
|
|
|
@ManyToMany
|
|
@JoinTable(
|
|
name = "recipe_viewer",
|
|
joinColumns = @JoinColumn(name = "recipe_id"),
|
|
inverseJoinColumns = @JoinColumn(name = "viewer_id")
|
|
)
|
|
private Set<User> viewers = new HashSet<>();
|
|
|
|
@ManyToOne
|
|
@JoinColumn(name = "main_image_id")
|
|
private Image mainImage;
|
|
|
|
@OneToOne(mappedBy = "recipe", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
|
|
private RecipeEmbeddingEntity embedding;
|
|
|
|
}
|