diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java index 7eb771dc2d56b0a221f636532f37825f519ccecc..991c53fb3721dbf5cfd86bf4f13f2c7d85cd742a 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java @@ -10,13 +10,14 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import ntnu.idatt2016.v233.SmartMat.entity.product.Product; +import ntnu.idatt2016.v233.SmartMat.entity.user.User; /** * Recipe is an entity class representing a recipe in the system. * - * @author Anders & Stian - * @version 1.0.001 - * @since 19.04.2023 + * @author Anders & Stian + Birk + * @version 1.1 + * @since 25.04.2023 * */ @@ -43,5 +44,9 @@ public class Recipe { inverseJoinColumns = @JoinColumn(name = "ean")) @JsonIgnoreProperties({"recipes"}) List<Product> products; + + @ManyToMany(mappedBy = "recipes") + @JsonIgnoreProperties({"recipes"}) + List<User> users; } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java index a04c39561bd8472c1fc0dc0af5f401618ba2d497..01ebf01dd306d5e85a6f039b8177558458f5bb20 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java @@ -9,6 +9,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import ntnu.idatt2016.v233.SmartMat.dto.enums.Authority; +import ntnu.idatt2016.v233.SmartMat.entity.Recipe; import ntnu.idatt2016.v233.SmartMat.entity.group.UserGroupAsso; import ntnu.idatt2016.v233.SmartMat.entity.product.Allergy; import org.springframework.security.core.GrantedAuthority; @@ -23,7 +24,7 @@ import java.util.*; * It implements the UserDetails interface. * * @author Anders and Birk - * @version 2.0.2 + * @version 2.0.3 * @since 25.04.2023 * */ @@ -74,6 +75,38 @@ public class User implements UserDetails { private List<Allergy> allergies; + @ManyToMany + @JoinTable( + name = "favorite_recipes", + joinColumns = @JoinColumn(name = "username"), + inverseJoinColumns = @JoinColumn(name = "recipe_id")) + @JsonIgnoreProperties({"users"}) + private List<Recipe> recipes; + + + /** + * adds an allergy to the user + * @param allergy the allergy to add to the user + */ + public void addAllergy(Allergy allergy){ + if (this.allergies == null) { + this.allergies = new ArrayList<>(); + } + this.allergies.add(allergy); + } + + /** + * adds a recipe to the user + * @param recipe the recipe to add to the user + */ + public void addRecipe(Recipe recipe){ + if (this.recipes == null) { + this.recipes = new ArrayList<>(); + } + this.recipes.add(recipe); + } + + /** * adds a group to the user * @param userGroupTable the userGroupTable to add to the user