Usamos o AllowFiltering no Repository, igual vimos no comando do cqlsh. Utilizaremos também, os query methods. Spring Data Cassandra Query Methods.
public interface ProductRepository extends CassandraRepository<Product, UUID> {
@AllowFiltering
List<Product> findProductsByDescription(String description);
}
Mesma lógica do anterior, se for nulo, retorna o findAll.
public List<ProductDTO> findByDescription(String description) {
List<Product> entity;
if ("".equals(description)) {
entity = repository.findAll();
} else {
entity = repository.findProductsByDescription(description);
}
return entity.stream().map(ProductDTO::new).toList();
}
Mesma lógica do anterior, se for nulo, retorna o findAll.
@GetMapping(value = "/description")
public ResponseEntity<List<ProductDTO>> findByDescription(
@RequestParam(name = "description", defaultValue = "") String description) {
if (description != null) {
List<ProductDTO> dto = productService.findByDescription(description);
return ResponseEntity.ok().body(dto);
} else {
List<ProductDTO> dto = productService.findAll();
return ResponseEntity.ok().body(dto);
}
}