misc: merge remote-tracking branch 'origin/main' into feature/ingredients-list
This commit is contained in:
commit
b1af6c1ef9
1 changed files with 26 additions and 66 deletions
|
|
@ -31,7 +31,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Collection;
|
||||
|
||||
// TABLE named recipes
|
||||
@Entity
|
||||
|
|
@ -48,45 +47,35 @@ public class Recipe {
|
|||
@Column(name = "name", nullable = false, unique = true)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates another table named recipe_ingredients which stores:
|
||||
* recipe_ingredients(recipe_id -> recipes(id), ingredient).
|
||||
* <p>
|
||||
* Example recipe_ingredients table:
|
||||
* <pre>
|
||||
* | recipe_id | ingredient |
|
||||
* |---------------------|------------|
|
||||
* | 0 (Chocolate Cake) | Egg |
|
||||
* | 0 (Chocolate Cake) | Egg |
|
||||
* | 0 (Chocolate Cake) | Flour |
|
||||
* | 1 (Steak) | 40g salt |
|
||||
* | 1 (Steak) | 40g pepper |
|
||||
* | 1 (Steak) | Meat |
|
||||
* |----------------------------------|
|
||||
* </pre>
|
||||
* TODO: Replace String with Embeddable Ingredient Class
|
||||
*/
|
||||
// Creates another table named recipe_ingredients which stores:
|
||||
// recipe_ingredients(recipe_id -> recipes(id), ingredient).
|
||||
// Example recipe_ingredients table:
|
||||
// | recipe_id | ingredient |
|
||||
// |---------------------|------------|
|
||||
// | 0 (Chocolate Cake) | Egg |
|
||||
// | 0 (Chocolate Cake) | Egg |
|
||||
// | 0 (Chocolate Cake) | Flour |
|
||||
// | 1 (Steak) | 40g salt |
|
||||
// | 1 (Steak) | 40g pepper |
|
||||
// | 1 (Steak) | Meat |
|
||||
// |----------------------------------|
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "recipe_ingredients", joinColumns = @JoinColumn(name = "recipe_id"))
|
||||
@Column(name = "ingredient")
|
||||
// TODO: Replace String with Embeddable Ingredient Class
|
||||
private List<String> ingredients = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates another table named recipe_preparation which stores:
|
||||
* recipe_preparation(recipe_id -> recipes(id), preparation_step, step_order).
|
||||
* <p>
|
||||
* Example recipe_preparation table:
|
||||
* <pre>
|
||||
* | recipe_id | preparation_step | step_order |
|
||||
* |---------------------|----------------------|------------|
|
||||
* | 0 (Chocolate Cake) | Preheat oven | 1 |
|
||||
* | 0 (Chocolate Cake) | Mix eggs and sugar | 2 |
|
||||
* | 0 (Chocolate Cake) | Add flour gradually | 3 |
|
||||
* | 1 (Steak) | Season meat | 1 |
|
||||
* | 1 (Steak) | Heat pan | 2 |
|
||||
* |---------------------------------------------------------|
|
||||
* </pre>
|
||||
*/
|
||||
// Creates another table named recipe_preparation which stores:
|
||||
// recipe_preparation(recipe_id -> recipes(id), preparation_step, step_order).
|
||||
// Example recipe_preparation table:
|
||||
// | recipe_id | preparation_step | step_order |
|
||||
// |---------------------|----------------------|------------|
|
||||
// | 0 (Chocolate Cake) | Preheat oven | 1 |
|
||||
// | 0 (Chocolate Cake) | Mix eggs and sugar | 2 |
|
||||
// | 0 (Chocolate Cake) | Add flour gradually | 3 |
|
||||
// | 1 (Steak) | Season meat | 1 |
|
||||
// | 1 (Steak) | Heat pan | 2 |
|
||||
// |---------------------------------------------------------|
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "recipe_preparation", joinColumns = @JoinColumn(name = "recipe_id"))
|
||||
@Column(name = "preparation_step")
|
||||
|
|
@ -129,16 +118,6 @@ public class Recipe {
|
|||
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
|
||||
public List<String> getIngredients() {
|
||||
// Disallow modifying the returned list.
|
||||
|
|
@ -146,22 +125,11 @@ public class Recipe {
|
|||
return Collections.unmodifiableList(ingredients);
|
||||
}
|
||||
|
||||
|
||||
// TODO: Replace String with Embeddable Ingredient Class
|
||||
public void setIngredients(List<String> 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() {
|
||||
// Disallow modifying the returned list.
|
||||
// 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")
|
||||
public String toDetailedString() {
|
||||
// More detailed toString for debugging.
|
||||
return "Recipe{" +
|
||||
"name='" + name + '\'' +
|
||||
", ingredients=" + ingredients +
|
||||
|
|
@ -213,4 +173,4 @@ public class Recipe {
|
|||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue