Skip to content
Snippets Groups Projects
Commit 3b9ece88 authored by Birk Øvstetun Narvhus's avatar Birk Øvstetun Narvhus
Browse files

added many to many connection

parent a47e19c2
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment