From a8f474e6edd9bf4ae2bd269859cfda32d615a1a0 Mon Sep 17 00:00:00 2001
From: birkon <birkon@stud.ntnu.no>
Date: Thu, 27 Apr 2023 15:09:04 +0200
Subject: [PATCH] changed add product to fridge controller

---
 .../v233/SmartMat/controller/ShoppingListController.java  | 8 +++++---
 .../v233/SmartMat/service/ShoppingListService.java        | 2 --
 2 files changed, 5 insertions(+), 5 deletions(-)

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 026aea33..15816caa 100644
--- a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java
+++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java
@@ -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());
 
 
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 c9ad82dd..5caae745 100644
--- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java
+++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java
@@ -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);
             });
         });
-- 
GitLab