diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java index be2ceaa5da6d94b5aad6f104beaa9cbe415bcb52..ce11ea30fa49c8725f8e6fb3a2eebc897b619dd2 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java @@ -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); diff --git a/target/classes/application.properties b/target/classes/application.properties index b13fdb2403ba71eb04d48c3180a862f33be4f843..0b2be5379b7e68fd12834a5ebbf3e40f67a27eab 100644 --- a/target/classes/application.properties +++ b/target/classes/application.properties @@ -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