Skip to content

Commit

Permalink
handle nullable filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker committed Dec 4, 2023
1 parent 2138c81 commit f2f11f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ProductDtoCrudService(ProductRepository productRepository, JpaFilterConve
}

@Override
public List<ProductDto> list(Pageable pageable, Filter filter) {
public List<ProductDto> list(Pageable pageable, @Nullable Filter filter) {
// Basic list implementation that only covers pagination,
// but not sorting or filtering
Page<Product> products = productRepository.findAll(pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.vaadin.flow.server.auth.AnonymousAllowed;
import dev.hilla.BrowserCallable;
import dev.hilla.Nullable;
import dev.hilla.crud.JpaFilterConverter;
import dev.hilla.crud.ListService;
import dev.hilla.crud.filter.Filter;
Expand All @@ -24,9 +25,11 @@ public ProductDtoListService(ProductRepository productRepository, JpaFilterConve
}

@Override
public List<ProductDto> list(Pageable pageable, Filter filter) {
public List<ProductDto> list(Pageable pageable, @Nullable Filter filter) {
// Use the Hilla JpaFilterConverter to create a JPA specification from the filter
Specification<Product> spec = jpaFilterConverter.toSpec(filter, Product.class);
Specification<Product> spec = filter != null
? jpaFilterConverter.toSpec(filter, Product.class)
: Specification.anyOf();
// Query the JPA repository
Page<Product> products = productRepository.findAll(spec, pageable);
// Map entities to DTOs and return result
Expand Down

0 comments on commit f2f11f3

Please sign in to comment.