V025 migration drops the column. Removed from Recipe entity, RecipeDetailResponse, RecipeSummaryResponse, RecipeRepository JPQL, RecipeService, and RecipeController. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
111 lines
3.7 KiB
Java
111 lines
3.7 KiB
Java
package com.recipeapp.recipe.entity;
|
|
|
|
import com.recipeapp.household.entity.Household;
|
|
import jakarta.persistence.*;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
|
|
@Entity
|
|
@Table(name = "recipe")
|
|
public class Recipe {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.UUID)
|
|
private UUID id;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "household_id", nullable = false)
|
|
private Household household;
|
|
|
|
@Column(nullable = false, length = 200)
|
|
private String name;
|
|
|
|
@Column(nullable = false)
|
|
private short serves;
|
|
|
|
@Column(name = "cook_time_min", nullable = false)
|
|
private short cookTimeMin;
|
|
|
|
@Column(nullable = false, length = 10)
|
|
private String effort;
|
|
|
|
@Column(name = "hero_image_url", columnDefinition = "text")
|
|
private String heroImageUrl;
|
|
|
|
@Column(name = "hero_image_preview", columnDefinition = "text")
|
|
private String heroImagePreview;
|
|
|
|
@Column(name = "deleted_at")
|
|
private Instant deletedAt;
|
|
|
|
@Column(name = "created_at", nullable = false, updatable = false)
|
|
private Instant createdAt;
|
|
|
|
@Column(name = "updated_at", nullable = false)
|
|
private Instant updatedAt;
|
|
|
|
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
@OrderBy("sortOrder")
|
|
private List<RecipeIngredient> ingredients = new ArrayList<>();
|
|
|
|
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
@OrderBy("stepNumber")
|
|
private List<RecipeStep> steps = new ArrayList<>();
|
|
|
|
@ManyToMany
|
|
@JoinTable(name = "recipe_tag",
|
|
joinColumns = @JoinColumn(name = "recipe_id"),
|
|
inverseJoinColumns = @JoinColumn(name = "tag_id"))
|
|
private Set<Tag> tags = new HashSet<>();
|
|
|
|
protected Recipe() {}
|
|
|
|
public Recipe(Household household, String name, short serves, short cookTimeMin, String effort) {
|
|
this.household = household;
|
|
this.name = name;
|
|
this.serves = serves;
|
|
this.cookTimeMin = cookTimeMin;
|
|
this.effort = effort;
|
|
}
|
|
|
|
@PrePersist
|
|
void onCreate() {
|
|
createdAt = Instant.now();
|
|
updatedAt = Instant.now();
|
|
}
|
|
|
|
@PreUpdate
|
|
void onUpdate() {
|
|
updatedAt = Instant.now();
|
|
}
|
|
|
|
public UUID getId() { return id; }
|
|
public Household getHousehold() { return household; }
|
|
public String getName() { return name; }
|
|
public void setName(String name) { this.name = name; }
|
|
public short getServes() { return serves; }
|
|
public void setServes(short serves) { this.serves = serves; }
|
|
public short getCookTimeMin() { return cookTimeMin; }
|
|
public void setCookTimeMin(short cookTimeMin) { this.cookTimeMin = cookTimeMin; }
|
|
public String getEffort() { return effort; }
|
|
public void setEffort(String effort) { this.effort = effort; }
|
|
public String getHeroImageUrl() { return heroImageUrl; }
|
|
public void setHeroImageUrl(String heroImageUrl) { this.heroImageUrl = heroImageUrl; }
|
|
public String getHeroImagePreview() { return heroImagePreview; }
|
|
public void setHeroImagePreview(String heroImagePreview) { this.heroImagePreview = heroImagePreview; }
|
|
public Instant getDeletedAt() { return deletedAt; }
|
|
public void setDeletedAt(Instant deletedAt) { this.deletedAt = deletedAt; }
|
|
public Instant getCreatedAt() { return createdAt; }
|
|
public Instant getUpdatedAt() { return updatedAt; }
|
|
public List<RecipeIngredient> getIngredients() { return ingredients; }
|
|
public List<RecipeStep> getSteps() { return steps; }
|
|
public Set<Tag> getTags() { return tags; }
|
|
public void setTags(Set<Tag> tags) { this.tags = tags; }
|
|
|
|
public boolean isDeleted() { return deletedAt != null; }
|
|
}
|