Created
September 25, 2022 10:16
-
-
Save GayanM/12d760020ce27ff8eef14590cb011cf2 to your computer and use it in GitHub Desktop.
Get a list of orders which were ordered on 15-Mar-2021, log the order records to the console and then return its product list
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("/log-orders") | |
| public List<Product> logOrdersOnGivenDateAndReturnProducts(@RequestParam("date") final Optional<String> date) { | |
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| return orderRepo.findAll().stream() | |
| .filter(o -> o.getOrderDate().isEqual(LocalDate.parse(date.get(), formatter))) | |
| .peek(o -> System.out.println(o.toString())) | |
| .flatMap(o -> o.getProducts().stream()) | |
| .distinct().map(p -> new Product(p.getId(), p.getName(), p.getPrice(), p.getCategory())) | |
| .collect(Collectors.toList()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment