Skip to content

Instantly share code, notes, and snippets.

@GayanM
Created September 25, 2022 10:10
Show Gist options
  • Select an option

  • Save GayanM/657da29b9a039345806f1ea9f79b8d55 to your computer and use it in GitHub Desktop.

Select an option

Save GayanM/657da29b9a039345806f1ea9f79b8d55 to your computer and use it in GitHub Desktop.
Get the 3 most recent placed order
@RequestMapping("/recent")
public List<Order> getRecentOrders (@RequestParam("limit") final Optional<Long> limit) {
return orderRepo.findAll().stream().
sorted(Comparator.
comparing(com.mycompany.functional.programming.exercises.models.Order::getOrderDate).
reversed()).limit(limit.get()).map(o -> new Order(o.getId(), o.getOrderDate(),
o.getDeliveryDate(), o.getStatus())).collect(Collectors.toList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment