mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
fix for recipe ingred steps ordering (hopefully)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.example.demo.entity;
|
package com.example.demo.entity;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
@@ -56,11 +58,15 @@ public class Recipe {
|
|||||||
// Recipe ingredients relationship
|
// Recipe ingredients relationship
|
||||||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||||
@NotEmpty(message = "At least one ingredient is required")
|
@NotEmpty(message = "At least one ingredient is required")
|
||||||
private Set<RecipeIngredient> recipeIngredients = new HashSet<>();
|
//hopfully add consistent order
|
||||||
|
@OrderBy("orderIndex ASC")
|
||||||
|
private List<RecipeIngredient> recipeIngredients = new ArrayList<>();
|
||||||
|
|
||||||
// Recipe Steps relationship
|
// Recipe Steps relationship
|
||||||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||||
private Set<Step> steps = new HashSet<>();
|
//hopefully to add order
|
||||||
|
@OrderBy("stepNumber ASC")
|
||||||
|
private List<Step> steps = new ArrayList<>();
|
||||||
|
|
||||||
// Recipe Images relationship
|
// Recipe Images relationship
|
||||||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||||
@@ -174,19 +180,19 @@ public class Recipe {
|
|||||||
this.updatedAt = updatedAt;
|
this.updatedAt = updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<RecipeIngredient> getRecipeIngredients() {
|
public List<RecipeIngredient> getRecipeIngredients(){
|
||||||
return recipeIngredients;
|
return recipeIngredients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRecipeIngredients(Set<RecipeIngredient> recipeIngredients) {
|
public void setRecipeIngredients(List<RecipeIngredient> recipeIngredients) {
|
||||||
this.recipeIngredients = recipeIngredients;
|
this.recipeIngredients = recipeIngredients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Step> getSteps() {
|
public List<Step> getSteps(){
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSteps(Set<Step> steps) {
|
public void setSteps(List<Step> steps) {
|
||||||
this.steps = steps;
|
this.steps = steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ public class RecipeIngredient {
|
|||||||
@Column(columnDefinition = "TEXT")
|
@Column(columnDefinition = "TEXT")
|
||||||
@Size(max = 128, message = "Note cannot be longer than 128 characters")
|
@Size(max = 128, message = "Note cannot be longer than 128 characters")
|
||||||
private String notes;
|
private String notes;
|
||||||
|
|
||||||
|
// To help keep in order
|
||||||
|
@Column(name = "order_index")
|
||||||
|
private Integer orderIndex;
|
||||||
|
|
||||||
public RecipeIngredient() {
|
public RecipeIngredient() {
|
||||||
}
|
}
|
||||||
@@ -99,4 +103,13 @@ public class RecipeIngredient {
|
|||||||
public void setNotes(String notes) {
|
public void setNotes(String notes) {
|
||||||
this.notes = notes;
|
this.notes = notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//to help keep in order
|
||||||
|
public Integer getOrderIndex() {
|
||||||
|
return orderIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderIndex(Integer orderIndex) {
|
||||||
|
this.orderIndex = orderIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Reference in New Issue
Block a user