misc: merge remote-tracking branch 'origin/main' into feature/ingredients-list

This commit is contained in:
Natalia Cholewa 2025-11-27 14:57:32 +01:00
commit b1af6c1ef9

View file

@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Collection;
// TABLE named recipes // TABLE named recipes
@Entity @Entity
@ -48,45 +47,35 @@ public class Recipe {
@Column(name = "name", nullable = false, unique = true) @Column(name = "name", nullable = false, unique = true)
private String name; private String name;
/** // Creates another table named recipe_ingredients which stores:
* Creates another table named recipe_ingredients which stores: // recipe_ingredients(recipe_id -> recipes(id), ingredient).
* recipe_ingredients(recipe_id -> recipes(id), ingredient). // Example recipe_ingredients table:
* <p> // | recipe_id | ingredient |
* Example recipe_ingredients table: // |---------------------|------------|
* <pre> // | 0 (Chocolate Cake) | Egg |
* | recipe_id | ingredient | // | 0 (Chocolate Cake) | Egg |
* |---------------------|------------| // | 0 (Chocolate Cake) | Flour |
* | 0 (Chocolate Cake) | Egg | // | 1 (Steak) | 40g salt |
* | 0 (Chocolate Cake) | Egg | // | 1 (Steak) | 40g pepper |
* | 0 (Chocolate Cake) | Flour | // | 1 (Steak) | Meat |
* | 1 (Steak) | 40g salt | // |----------------------------------|
* | 1 (Steak) | 40g pepper |
* | 1 (Steak) | Meat |
* |----------------------------------|
* </pre>
* TODO: Replace String with Embeddable Ingredient Class
*/
@ElementCollection @ElementCollection
@CollectionTable(name = "recipe_ingredients", joinColumns = @JoinColumn(name = "recipe_id")) @CollectionTable(name = "recipe_ingredients", joinColumns = @JoinColumn(name = "recipe_id"))
@Column(name = "ingredient") @Column(name = "ingredient")
// TODO: Replace String with Embeddable Ingredient Class
private List<String> ingredients = new ArrayList<>(); private List<String> ingredients = new ArrayList<>();
/** // Creates another table named recipe_preparation which stores:
* Creates another table named recipe_preparation which stores: // recipe_preparation(recipe_id -> recipes(id), preparation_step, step_order).
* recipe_preparation(recipe_id -> recipes(id), preparation_step, step_order). // Example recipe_preparation table:
* <p> // | recipe_id | preparation_step | step_order |
* Example recipe_preparation table: // |---------------------|----------------------|------------|
* <pre> // | 0 (Chocolate Cake) | Preheat oven | 1 |
* | recipe_id | preparation_step | step_order | // | 0 (Chocolate Cake) | Mix eggs and sugar | 2 |
* |---------------------|----------------------|------------| // | 0 (Chocolate Cake) | Add flour gradually | 3 |
* | 0 (Chocolate Cake) | Preheat oven | 1 | // | 1 (Steak) | Season meat | 1 |
* | 0 (Chocolate Cake) | Mix eggs and sugar | 2 | // | 1 (Steak) | Heat pan | 2 |
* | 0 (Chocolate Cake) | Add flour gradually | 3 | // |---------------------------------------------------------|
* | 1 (Steak) | Season meat | 1 |
* | 1 (Steak) | Heat pan | 2 |
* |---------------------------------------------------------|
* </pre>
*/
@ElementCollection @ElementCollection
@CollectionTable(name = "recipe_preparation", joinColumns = @JoinColumn(name = "recipe_id")) @CollectionTable(name = "recipe_preparation", joinColumns = @JoinColumn(name = "recipe_id"))
@Column(name = "preparation_step") @Column(name = "preparation_step")
@ -129,16 +118,6 @@ public class Recipe {
this.name = name; this.name = name;
} }
/**
* Returns an unmodifiable view of the ingredients list.
* <p>
* The returned list cannot be modified directly. To modify ingredients,
* create a copy using {@link List#copyOf(Collection)} or create your own list,
* populate it, and use {@link #setIngredients(List)} to update.
*
* @return An unmodifiable list of ingredients.
* @see #setIngredients(List)
*/
// TODO: Replace String with Embeddable Ingredient Class // TODO: Replace String with Embeddable Ingredient Class
public List<String> getIngredients() { public List<String> getIngredients() {
// Disallow modifying the returned list. // Disallow modifying the returned list.
@ -146,22 +125,11 @@ public class Recipe {
return Collections.unmodifiableList(ingredients); return Collections.unmodifiableList(ingredients);
} }
// TODO: Replace String with Embeddable Ingredient Class // TODO: Replace String with Embeddable Ingredient Class
public void setIngredients(List<String> ingredients) { public void setIngredients(List<String> ingredients) {
this.ingredients = ingredients; this.ingredients = ingredients;
} }
/**
* Returns an unmodifiable view of the preparation steps list.
* <p>
* The returned list cannot be modified directly. To modify preparation steps,
* create a copy using {@link List#copyOf(Collection)} or create your own list,
* populate it, and use {@link #setPreparationSteps(List)} to update.
*
* @return An unmodifiable list of preparation steps in order.
* @see #setPreparationSteps(List)
*/
public List<String> getPreparationSteps() { public List<String> getPreparationSteps() {
// Disallow modifying the returned list. // Disallow modifying the returned list.
// You can still copy it with List.copyOf(...) // You can still copy it with List.copyOf(...)
@ -195,17 +163,9 @@ public class Recipe {
"}"; "}";
} }
/**
* Returns a more detailed string than {@link #toString()} of this recipe, including
* the full contents of all ingredients and preparation steps.
* <p>
* Intended only for debugging.
*
* @return A detailed string representation containing all recipe data.
* @see #toString()
*/
@SuppressWarnings("unused") @SuppressWarnings("unused")
public String toDetailedString() { public String toDetailedString() {
// More detailed toString for debugging.
return "Recipe{" + return "Recipe{" +
"name='" + name + '\'' + "name='" + name + '\'' +
", ingredients=" + ingredients + ", ingredients=" + ingredients +
@ -213,4 +173,4 @@ public class Recipe {
'}'; '}';
} }
} }