Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(method = RequestMethod.GET)
- public Page<Product> find(
- @PageableDefault(sort = "id", direction = DESC) final Pageable pageable,
- @RequestParam(required = false) final String nameLike,
- @RequestParam(required = false) final Long priceFrom,
- @RequestParam(required = false) final Long priceTo,
- @RequestParam(defaultValue = "true") final boolean inStock,
- @RequestParam(required = false) final Set<String> categoriesIn) {
- final Specifications<Product> specifications = SpecificationBuilder.where(stockAvaiable(inStock))
- .and(nameLike, StringUtils::isNotEmpty, ProductSpecifications::nameLike)
- .and(priceFrom, Objects::nonNull, ProductSpecifications::priceGraterThanOrEqualsTo)
- .and(priceTo, Objects::nonNull, ProductSpecifications::priceLessThan)
- .and(categoriesIn, CollectionUtils::isNotEmpty, ProductSpecifications::categoriesIn)
- .build();
- return repository.findAll(specifications, pageable);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement