Skip to content

Instantly share code, notes, and snippets.

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

  • Save GayanM/12d760020ce27ff8eef14590cb011cf2 to your computer and use it in GitHub Desktop.

Select an option

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
@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