Skip to content

Instantly share code, notes, and snippets.

@GayanM
Created September 25, 2022 10:59
Show Gist options
  • Save GayanM/61cbc361895365017605c9526267a71a to your computer and use it in GitHub Desktop.
Save GayanM/61cbc361895365017605c9526267a71a to your computer and use it in GitHub Desktop.
Obtain a data map with order id and order’s product count
@RequestMapping("/products-count")
public Map<Long, Integer> getOrdersWithProductCount() {
return orderRepo.findAll().stream().
collect(Collectors.toMap(o -> o.getId(), o -> o.getProducts().size()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment