diff --git a/src/main/java/com/example/hangry/Ingredient.java b/src/main/java/com/example/hangry/Ingredient.java new file mode 100644 index 0000000..b1ce6eb --- /dev/null +++ b/src/main/java/com/example/hangry/Ingredient.java @@ -0,0 +1,40 @@ +package com.example.hangry; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Ingredient { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; // Name der Zutat + + public Ingredient() { + } + + public Ingredient(String name) { + this.name = name; + } + + // Getter und Setter + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/example/hangry/Recipe.java b/src/main/java/com/example/hangry/Recipe.java index 575cf3b..06f015c 100644 --- a/src/main/java/com/example/hangry/Recipe.java +++ b/src/main/java/com/example/hangry/Recipe.java @@ -1,9 +1,7 @@ package com.example.hangry; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; +import java.util.List; @Entity public class Recipe { @@ -14,13 +12,20 @@ public class Recipe { private String name; private String description; + private String category; + private String imageUrl; + + @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true) + private List recipeIngredients; public Recipe() { } - public Recipe(String name, String description) { + public Recipe(String name, String description, String category, String imageUrl) { this.name = name; this.description = description; + this.category = category; + this.imageUrl = imageUrl; } // Getter und Setter @@ -47,4 +52,28 @@ public class Recipe { public void setDescription(String description) { this.description = description; } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public List getRecipeIngredients() { + return recipeIngredients; + } + + public void setRecipeIngredients(List recipeIngredients) { + this.recipeIngredients = recipeIngredients; + } } diff --git a/src/main/java/com/example/hangry/RecipeIngredient.java b/src/main/java/com/example/hangry/RecipeIngredient.java new file mode 100644 index 0000000..138ab61 --- /dev/null +++ b/src/main/java/com/example/hangry/RecipeIngredient.java @@ -0,0 +1,73 @@ +package com.example.hangry; + +import jakarta.persistence.*; + +@Entity +public class RecipeIngredient { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "recipe_id", nullable = false) + private Recipe recipe; + + @ManyToOne + @JoinColumn(name = "ingredient_id", nullable = false) + private Ingredient ingredient; + + private String amount; // Menge, z. B. "200 g" + private String unit; // Einheit, z. B. "g", "ml", "Stück" + + public RecipeIngredient() { + } + + public RecipeIngredient(Recipe recipe, Ingredient ingredient, String amount, String unit) { + this.recipe = recipe; + this.ingredient = ingredient; + this.amount = amount; + this.unit = unit; + } + + // Getter und Setter + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Recipe getRecipe() { + return recipe; + } + + public void setRecipe(Recipe recipe) { + this.recipe = recipe; + } + + public Ingredient getIngredient() { + return ingredient; + } + + public void setIngredient(Ingredient ingredient) { + this.ingredient = ingredient; + } + + public String getAmount() { + return amount; + } + + public void setAmount(String amount) { + this.amount = amount; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } +}