Skip to content
Snippets Groups Projects
Commit beb1de84 authored by Pedro Pablo Cardona Arroyave's avatar Pedro Pablo Cardona Arroyave
Browse files

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
......@@ -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);
......
......@@ -5,7 +5,7 @@ spring.datasource.username=smartmat_user
spring.datasource.password=Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC
# jpa settings
spring.jpa.show-sql=true
spring.jpa.show-sql=false
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
......
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