Untitled
unknown
plain_text
2 years ago
1.6 kB
1
Indexable
Never
.orElseThrow(() -> new EKartCustomerCartException("CustomerCartService.NO_CART_FOUND")); if(cart.getCartProducts().isEmpty()){ throw new EKartCustomerCartException("CustomerCartService.NO_PRODUCT_ADDED_TO_CART"); } CartProductselectedProduct=null; for(CartProductproduct:cart.getCartProducts()){ if(product.getProductId().equals(productId)){ selectedProduct=product; } } if(selectedProduct==null){ throw new EKartCustomerCartException("CustomerCartService.PRODUCT_ALREADY_NOT_AVAILABLE"); } cart.getCartProducts().remove(selectedProduct); cartProductRepository.delete(selectedProduct); } @Override public void deleteAllProductsFromCart(String customerEmailId) throws EKartCustomerCartException{ Optional<CustomerCart> cartOptional = customerCartRepository.findByCustomerEmailId(customerEmailId); CustomerCartcart=cartOptional .orElseThrow(() -> new EKartCustomerCartException("CustomerCartService.NO_CART_FOUND")); if(cart.getCartProducts().isEmpty()){ throw new EKartCustomerCartException("CustomerCartService.NO_PRODUCT_ADDED_TO_CART"); } List<Integer>productIds=newArrayList<>(); cart.getCartProducts().parallelStream().forEach(cp->{ productIds.add(cp.getCartProductId()); cart.getCartProducts().remove(cp); }); productIds.forEach(pid->{ cartProductRepository.deleteById(pid); }); } @Override publicvoidmodifyQuantityOfProductInCart(StringcustomerEmailId,IntegerproductId, Integerquantity) throwsEKartCustomerCartException{ Optional<CustomerCart> cartOptional = customerCartRepository.findByCustomerEmailId(customerEmailId); CustomerCartcart=cartOptional .orElseThrow(() -> new