From beb1de847be9defc567b31d38322de57c0dd5fa2 Mon Sep 17 00:00:00 2001 From: Pedro Cardona <pedropca@stud.ntnu.no> Date: Wed, 3 May 2023 11:49:42 +0200 Subject: [PATCH] A product may be marked as not-vegan, not-vegetarian and haram --- .../controller/product/ProductController.java | 22 +++++++++++++++++++ target/classes/application.properties | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) 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 be2ceaa5..ce11ea30 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 b13fdb24..0b2be537 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 -- GitLab