Skip to content
Snippets Groups Projects
Commit a8f474e6 authored by Birk Øvstetun Narvhus's avatar Birk Øvstetun Narvhus
Browse files

changed add product to fridge controller

parent 86aad1c8
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import java.util.Optional;
import ntnu.idatt2016.v233.SmartMat.entity.product.Product;
import ntnu.idatt2016.v233.SmartMat.entity.user.User;
import ntnu.idatt2016.v233.SmartMat.service.product.ProductService;
import ntnu.idatt2016.v233.SmartMat.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -34,6 +35,7 @@ public class ShoppingListController {
UserService userService;
/**
* Gets a shopping list by its ID
*
......@@ -93,10 +95,10 @@ public class ShoppingListController {
if(product.isPresent())
return ResponseEntity.status(HttpStatus.CONFLICT).build();
Optional<ShoppingList> returnVal = shoppingListService
.addProductToShoppingList(shoppingListId, Long.parseLong(ean));
Optional<ShoppingList> returnval = shoppingListService.addProductToShoppingList(shoppingList.get().getShoppingListID(),
Long.parseLong(ean));
return returnVal.map(list -> ResponseEntity.status(HttpStatus.OK).body(list))
return returnval.map(list -> ResponseEntity.status(HttpStatus.OK).body(list))
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build());
......
......@@ -78,8 +78,6 @@ public class ShoppingListService {
shoppingListRepository.findById(shoppingListId).ifPresent(shoppingList -> {
productRepository.findById(ean).ifPresent(product -> {
shoppingList.addProduct(product);
product.addShoppingList(shoppingList);
productRepository.save(product);
shoppingListRepository.save(shoppingList);
});
});
......
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