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) {
- Specifications<Product> specifications = Specifications.where(stockAvaiable(inStock));
- if (StringUtils.isNotEmpty(nameLike)) {
- specifications = specifications.and(nameLike(nameLike));
- }
- if (Objects.nonNull(priceFrom)) {
- specifications = specifications.and(priceGraterThanOrEqualsTo(priceFrom));
- }
- if (Objects.nonNull(priceTo)) {
- specifications = specifications.and(priceLessThan(priceTo));
- }
- if (CollectionUtils.isNotEmpty(categoriesIn)) {
- specifications = specifications.and(categoriesIn(categoriesIn));
- }
- specifications = specifications.and(stockAvaiable(inStock));
- return repository.findAll(specifications, pageable);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement