From 69d823c977cdafd61c1781576f66733e1e347f79 Mon Sep 17 00:00:00 2001 From: durn Date: Tue, 21 Apr 2026 18:24:46 -0600 Subject: [PATCH] got rid of odd duplicate lines --- .../java/com/example/demo/entity/Recipe.java | 21 ++++++++++++------- .../example/demo/entity/RecipeIngredient.java | 15 ++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/demo/entity/Recipe.java b/src/main/java/com/example/demo/entity/Recipe.java index 3acf02d..16efc25 100644 --- a/src/main/java/com/example/demo/entity/Recipe.java +++ b/src/main/java/com/example/demo/entity/Recipe.java @@ -1,6 +1,8 @@ package com.example.demo.entity; import jakarta.persistence.*; +import java.util.List; +import java.util.ArrayList; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -56,11 +58,13 @@ public class Recipe { // Recipe ingredients relationship @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @NotEmpty(message = "At least one ingredient is required") - private Set recipeIngredients = new HashSet<>(); - + @OrderBy("orderIndex ASC") + private List recipeIngredients = new ArrayList<>(); + // Recipe Steps relationship @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - private Set steps = new HashSet<>(); + @OrderBy("stepNumber ASC") + private List steps = new ArrayList<>(); // Recipe Images relationship @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @@ -172,21 +176,22 @@ public class Recipe { public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; + this.updatedAt = updatedAt; } - public Set getRecipeIngredients() { + public List getRecipeIngredients(){ return recipeIngredients; } - public void setRecipeIngredients(Set recipeIngredients) { + public void setRecipeIngredients(List recipeIngredients) { this.recipeIngredients = recipeIngredients; } - public Set getSteps() { + public List getSteps(){ return steps; } - public void setSteps(Set steps) { + public void setSteps(List steps) { this.steps = steps; } @@ -221,4 +226,4 @@ public class Recipe { public void setCost(Integer cost) { this.cost = cost; } -} \ No newline at end of file +} diff --git a/src/main/java/com/example/demo/entity/RecipeIngredient.java b/src/main/java/com/example/demo/entity/RecipeIngredient.java index 6f6f98d..0590d03 100644 --- a/src/main/java/com/example/demo/entity/RecipeIngredient.java +++ b/src/main/java/com/example/demo/entity/RecipeIngredient.java @@ -39,6 +39,10 @@ public class RecipeIngredient { @Column(columnDefinition = "TEXT") @Size(max = 128, message = "Note cannot be longer than 128 characters") private String notes; + + // To help keep in order + @Column(name = "order_index") + private Integer orderIndex; public RecipeIngredient() { } @@ -99,4 +103,13 @@ public class RecipeIngredient { public void setNotes(String notes) { this.notes = notes; } -} \ No newline at end of file + + //to help keep in order + public Integer getOrderIndex() { + return orderIndex; + } + + public void setOrderIndex(Integer orderIndex) { + this.orderIndex = orderIndex; + } +}