Created
September 25, 2022 10:10
-
-
Save GayanM/657da29b9a039345806f1ea9f79b8d55 to your computer and use it in GitHub Desktop.
Get the 3 most recent placed order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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