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
beb1de84
Commit
beb1de84
authored
1 year ago
by
Pedro Pablo Cardona Arroyave
Browse files
Options
Downloads
Patches
Plain Diff
A product may be marked as not-vegan, not-vegetarian and haram
parent
34c1151d
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/controller/product/ProductController.java
+22
-0
22 additions, 0 deletions
...6/v233/SmartMat/controller/product/ProductController.java
target/classes/application.properties
+1
-1
1 addition, 1 deletion
target/classes/application.properties
with
23 additions
and
1 deletion
src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java
+
22
−
0
View file @
beb1de84
...
...
@@ -2,12 +2,14 @@ package ntnu.idatt2016.v233.SmartMat.controller.product;
import
lombok.AllArgsConstructor
;
import
ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Allergy
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Category
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Product
;
import
ntnu.idatt2016.v233.SmartMat.service.AllergyService
;
import
ntnu.idatt2016.v233.SmartMat.service.product.CategoryService
;
import
ntnu.idatt2016.v233.SmartMat.service.product.ProductService
;
import
ntnu.idatt2016.v233.SmartMat.util.CategoryUtil
;
import
ntnu.idatt2016.v233.SmartMat.util.ProductUtil
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -85,6 +87,26 @@ public class ProductController {
});
});
}
boolean
vegan
=
CategoryUtil
.
isVegan
(
product
.
getName
(),
product
.
getDescription
());
if
(!
vegan
){
Allergy
allergy
=
allergyService
.
getAllergyByName
(
"ikke vegansk"
).
get
();
product
.
addAllergy
(
allergy
);
allergy
.
addProduct
(
product
);
allergy
=
allergyService
.
getAllergyByName
(
"Ikke vegetariansk"
).
get
();
product
.
addAllergy
(
allergy
);
allergy
.
addProduct
(
product
);
}
boolean
vegetarian
=
CategoryUtil
.
isVegetarian
(
product
.
getName
(),
product
.
getDescription
(),
vegan
);
if
(!
vegetarian
){
Allergy
allergy
=
allergyService
.
getAllergyByName
(
"ikke vegetariansk"
).
get
();
product
.
addAllergy
(
allergy
);
allergy
.
addProduct
(
product
);
}
if
(!
CategoryUtil
.
isHalal
(
product
.
getName
(),
product
.
getDescription
(),
vegetarian
)){
Allergy
allergy
=
allergyService
.
getAllergyByName
(
"Haram"
).
get
()
;
product
.
addAllergy
(
allergy
);
allergy
.
addProduct
(
product
);
}
productService
.
saveProduct
(
product
);
return
ResponseEntity
.
ok
(
product
);
...
...
This diff is collapsed.
Click to expand it.
target/classes/application.properties
+
1
−
1
View file @
beb1de84
...
...
@@ -5,7 +5,7 @@ spring.datasource.username=smartmat_user
spring.datasource.password
=
Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC
# jpa settings
spring.jpa.show-sql
=
tru
e
spring.jpa.show-sql
=
fals
e
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
...
...
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