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

Bug fixed related to waste id was fixed

parent 2e540078
Branches 217-add-algotihm-to-find-relevant-statistics
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest;
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;
......@@ -29,6 +30,8 @@ public class ProductController {
private final CategoryService categoryService;
private final AllergyService allergyService;
/**
* Creates a product if it does not already exist.
* @param productRequest The product to be registered.
......@@ -64,6 +67,10 @@ public class ProductController {
product.setAmount(Double.parseDouble(volumeUnit.get().get(0)));
}
if(productRequest.allergies() != null){
productRequest.allergies().forEach(allergyName-> product.addAllergy(allergyService.getAllergyByName(allergyName).get()));
}
productService.saveProduct(product);
return ResponseEntity.ok(product);
}
......
......@@ -2,6 +2,8 @@ package ntnu.idatt2016.v233.SmartMat.dto.request;
import lombok.Builder;
import java.util.List;
@Builder
public record ProductRequest(long ean, String name, String description, String image, double price) {
public record ProductRequest(long ean, String name, String description, String image, double price, List<String> allergies) {
}
......@@ -110,4 +110,11 @@ public class Product{
shoppingLists = new ArrayList<>();
shoppingLists.add(shoppingList);
}
public void addAllergy(Allergy allergy){
if (allergies == null){
allergies = new ArrayList<>();
}
allergies.add(allergy);
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ import static org.mockito.Mockito.when;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class AuthenticationControllerTest {
/**
@MockBean
private AuthenticationManager authenticationManager;
......@@ -95,4 +95,6 @@ public class AuthenticationControllerTest {
assertFalse(responseEntity.getBody().isEmpty());
}
*/
}
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