in dashboard-web-app/src/main/java/org/inventory/hub/controller/ProductsInventoryController.java [46:78]
public ResponseEntity<?> getProduct(@PathVariable("productName") String productName) {
try {
final Flux<ProductsInventory> productsInventoriesFlux = productsInventoryRepository.findAll();
final Iterable<ProductsInventory> productsInventories = productsInventoriesFlux.toIterable();
final ResponseEntity<Iterable<ProductsInventory>> productInventories =
new ResponseEntity<Iterable<ProductsInventory>>(productsInventories, HttpStatus.OK);
System.out.println("======= /api/products/{productName} ===== ");
System.out.println(productInventories.toString());
final Iterable <ProductsInventory> iterable = (Iterable<ProductsInventory>) productInventories.getBody();
final Iterator <ProductsInventory> it = makeCollection(iterable).iterator();
final Product product = new Product();
ProductsInventory productInventory = null;
while (it.hasNext()) {
productInventory = it.next();
product.setName(productInventory.getProductName());
product.getCountByLocation()
.put(productInventory.getLocation(),
Integer.valueOf(productInventory.getTotalCount()));
}
return new ResponseEntity<Product> (product, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<String>(productName + " not found",
HttpStatus.NOT_FOUND);
}
}