diff --git a/src/main/java/com/example/demo/entity/Recipe.java b/src/main/java/com/example/demo/entity/Recipe.java index 3acf02d..e75113f 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,15 @@ 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<>(); - + //hopfully add consistent order + @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<>(); + //hopefully to add order + @OrderBy("stepNumber ASC") + private List steps = new ArrayList<>(); // Recipe Images relationship @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @@ -174,19 +180,19 @@ public class Recipe { 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; } diff --git a/src/main/java/com/example/demo/entity/RecipeIngredient.java b/src/main/java/com/example/demo/entity/RecipeIngredient.java index 6f6f98d..230e72f 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; } + + //to help keep in order + public Integer getOrderIndex() { + return orderIndex; + } + + public void setOrderIndex(Integer orderIndex) { + this.orderIndex = orderIndex; + } } \ No newline at end of file diff --git a/uploads/ea91b0a9-f2b8-4401-a282-0d6919a98934.jpg b/uploads/ea91b0a9-f2b8-4401-a282-0d6919a98934.jpg new file mode 100644 index 0000000..0c8dc24 Binary files /dev/null and b/uploads/ea91b0a9-f2b8-4401-a282-0d6919a98934.jpg differ