diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java index 103d16a027787af01f48ee2589928cf27e717b53..352447b28b4114bf14b0b099861f19b9a1580c34 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java @@ -134,8 +134,10 @@ public class ShoppingListController { if(product.isEmpty()) return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + System.out.println("Removing product from shopping list : " + shoppingListId + " - " + ean); + Optional<ShoppingList> returnVal = shoppingListService - .removeProductFromShoppingList(Long.parseLong(shoppingListId), Long.parseLong(ean)); + .removeProductFromShoppingList(Long.parseLong(ean), Long.parseLong(shoppingListId)); return returnVal.map(list -> ResponseEntity.status(HttpStatus.OK).body(list)) .orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build()); diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java index 9472a997f4370293de486a34dfafbfc664045edf..c7867e9c482e064e58117c78f316d604d4aed7f6 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java @@ -93,13 +93,14 @@ public class ShoppingListService { * @return the shopping list that the product was removed from */ public Optional<ShoppingList> removeProductFromShoppingList(long ean, long shoppingListId){ + System.out.println("shopping list status : " + shoppingListRepository.findById(shoppingListId).isPresent()); + shoppingListRepository.findById(shoppingListId).ifPresent(shoppingList -> { - productRepository.findById(ean).ifPresent(product -> { - shoppingList.getProducts().remove(product); - product.getShoppingLists().remove(shoppingList); - productRepository.save(product); - shoppingListRepository.save(shoppingList); - }); + productRepository.findById(ean).ifPresent(product -> { + shoppingList.getProducts().remove(product); + product.getShoppingLists().remove(shoppingList); + shoppingListRepository.save(shoppingList); + }); }); return shoppingListRepository.findById(shoppingListId);