Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106-v23-03
backend
Commits
3b9ece88
Commit
3b9ece88
authored
2 years ago
by
Birk Øvstetun Narvhus
Browse files
Options
Downloads
Patches
Plain Diff
added many to many connection
parent
a47e19c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java
+8
-3
8 additions, 3 deletions
...main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java
src/main/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java
+34
-1
34 additions, 1 deletion
...n/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java
with
42 additions
and
4 deletions
src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Recipe.java
+
8
−
3
View file @
3b9ece88
...
...
@@ -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.00
1
* @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
;
}
This diff is collapsed.
Click to expand it.
src/main/java/ntnu/idatt2016/v233/SmartMat/entity/user/User.java
+
34
−
1
View file @
3b9ece88
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment