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()); | |
| } |
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("/cheapest") | |
| public Optional<Product> getCheapestProductByCategory(@RequestParam("category") final Optional<String> category) { | |
| return productRepos.findAll().stream().filter(p -> { | |
| if (category.isEmpty()) { | |
| return true; | |
| } | |
| return category.get().equalsIgnoreCase(p.getCategory()); | |
| }).min(Comparator.comparing(com.mycompany.functional.programming.exercises.models.Product::getPrice)).map(p -> | |
| new Product(p.getId(), p.getName(), p.getPrice(), p.getCategory())); | |
| } |
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("/customer-tier") | |
| public List<Product> getProductsByCustomerTier (@RequestParam("tier") final Optional<Integer> tier, | |
| @RequestParam("start-date") final Optional<String> startDate, | |
| @RequestParam("end-date") final Optional<String> endDate) { | |
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| return orderRepo.findAll().stream(). | |
| filter(o -> { | |
| if (tier.isEmpty()) { | |
| return true; | |
| } |
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("/discount") | |
| public List<Product> applyDiscountOnCategory(@RequestParam("category") final Optional<String> category, | |
| @RequestParam("discount") final Optional<Double> discount) { | |
| return productRepos.findAll().stream(). | |
| filter(p -> { | |
| if (category.isEmpty()) { | |
| return true; | |
| } | |
| return category.get().equalsIgnoreCase(p.getCategory()); | |
| }).map(p -> { |
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("") | |
| public List<Order> getOrdersByProductCategory (@RequestParam("category") final Optional<String> category) { | |
| return orderRepo.findAll().stream(). | |
| filter(o -> o.getProducts().stream().anyMatch(p -> { | |
| if (category.isEmpty()) { | |
| return true; | |
| } | |
| return category.get().equalsIgnoreCase(p.getCategory()); | |
| })). | |
| map(o -> new Order(o.getId(), o.getOrderDate(), o.getDeliveryDate(), o.getStatus())). |
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("") | |
| public List<Product> filterProducts(@Param("category") final Optional<String> category, | |
| @Param("lower-price-limit") final Optional<Double> lowerLimitPrice, | |
| @RequestParam("upper-price-limit") final Optional<Double> upperLimitPrice ) { | |
| return productRepos.findAll().stream(). | |
| filter(p -> { | |
| if (category.isEmpty()) { | |
| return true; |
NewerOlder