Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. @RequestMapping(method = RequestMethod.GET)
  2. public Page<Product> find(
  3. @PageableDefault(sort = "id", direction = DESC) final Pageable pageable,
  4. @RequestParam(required = false) final String nameLike,
  5. @RequestParam(required = false) final Long priceFrom,
  6. @RequestParam(required = false) final Long priceTo,
  7. @RequestParam(defaultValue = "true") final boolean inStock,
  8. @RequestParam(required = false) final Set<String> categoriesIn) {
  9.  
  10. final Specifications<Product> specifications = SpecificationBuilder.where(stockAvaiable(inStock))
  11. .and(nameLike, StringUtils::isNotEmpty, ProductSpecifications::nameLike)
  12. .and(priceFrom, Objects::nonNull, ProductSpecifications::priceGraterThanOrEqualsTo)
  13. .and(priceTo, Objects::nonNull, ProductSpecifications::priceLessThan)
  14. .and(categoriesIn, CollectionUtils::isNotEmpty, ProductSpecifications::categoriesIn)
  15. .build();
  16.  
  17. return repository.findAll(specifications, pageable);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement