Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 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. Specifications<Product> specifications = Specifications.where(stockAvaiable(inStock));
  11.  
  12. if (StringUtils.isNotEmpty(nameLike)) {
  13. specifications = specifications.and(nameLike(nameLike));
  14. }
  15. if (Objects.nonNull(priceFrom)) {
  16. specifications = specifications.and(priceGraterThanOrEqualsTo(priceFrom));
  17. }
  18. if (Objects.nonNull(priceTo)) {
  19. specifications = specifications.and(priceLessThan(priceTo));
  20. }
  21. if (CollectionUtils.isNotEmpty(categoriesIn)) {
  22. specifications = specifications.and(categoriesIn(categoriesIn));
  23. }
  24. specifications = specifications.and(stockAvaiable(inStock));
  25.  
  26. return repository.findAll(specifications, pageable);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement