public void processOrder(String productId, long quantity) { Product productById = productRepository.getProductById(productId); if (productById.getUnitsInStock() < quantity) { throw new IllegalArgumentException( "Out of stock. Available units in stock" + productById.getUnitsInStock()); } productById.setUnitsInStock(productById.getUnitsInStock() - quantity); }
@Override public void addProduct(Product product) { productRepository.addProduct(product); }
@Override public Set<Product> getProductsBypriceFilter(Map<String, List<String>> filterParams) { return productRepository.getProductsBypriceFilter(filterParams); }
@Override public List<Product> getProductsByManufacturer(String manufacturer) { return productRepository.getProductsByManufacturer(manufacturer); }
@Override public List<Product> getProductsByCategory(String category) { return productRepository.getProductsByCategory(category); }
@Override public Product getProductById(String productId) { return productRepository.getProductById(productId); }
@Override public List<Product> getAllProducts() { return productRepository.getAllProducts(); }