@RequestMapping(value = "/{basketId}/remove/{productId}", method = RequestMethod.DELETE) ResponseEntity<Basket> remove(@PathVariable String basketId, @PathVariable String productId) { log.debug("Basket #" + basketId + " Add Product#" + productId); Product product = productrepository.getProduct(productId); Basket basket = basketRepository.findOne(basketId); if (basket.getProducts() != null) { basket.getProducts().remove(product); } basketRepository.save(basket); basket = basketRepository.findOne(basketId); return new ResponseEntity<>(basket, null, HttpStatus.OK); }
@RequestMapping(value = "/{basketId}/add/{productId}", method = RequestMethod.PUT) ResponseEntity<Basket> add(@PathVariable String basketId, @PathVariable String productId) { log.debug("Basket #" + basketId + " Add Product#" + productId); Product product = productrepository.getProduct(productId); Basket basket = basketRepository.findOne(basketId); if (basket.getProducts() != null) { basket.getProducts().add(product); } else { basket.setProducts(new ArrayList<>()); basket.getProducts().add(product); } basketRepository.save(basket); basket = basketRepository.findOne(basketId); return new ResponseEntity<>(basket, null, HttpStatus.OK); }