Estou tentando passar uma lista como argumento mas não está funcionando pois precisa ter o parâmetro na entidade. Veja o erro que está retornando:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consultaIndicadoresDataSource' defined in file [C:\Workspace\ConsultaIndicadoresDataSource.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'consultaIndicadoresRepository' defined in br.com.b3.dadd.indicadores.investimentos.datasources.repository.ConsultaIndicadoresRepository defined in @EnableJpaRepositories declared on IndicadoresInvestimentos: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List indicadores.investimentos.datasources.repository.ConsultaIndicadoresRepository.findByNumeroCpfAndDomain(java.lang.String,java.util.List)! Reason: Failed to create query for method public abstract java.util.List .indicadores.investimentos.datasources.repository.ConsultaIndicadoresRepository.findByNumeroCpfAndDomain(java.lang.String,java.util.List)! No property domain found for type DadosIndicadoresEntity!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List .indicadores.investimentos.datasources.repository.ConsultaIndicadoresRepository.findByNumeroCpfAndDomain(java.lang.String,java.util.List)! No property domain found for type DadosIndicadoresEntity!
Repository:
@Repository
public interface ConsultaIndicadoresRepository extends JpaRepository<DadosIndicadoresEntity, String> {
DadosIndicadoresEntity findByNumeroCpfAndData(String numeroCpf, Date data);
List<DadosIndicadoresEntity> findByNumeroCpfAndDomain(String numeroCpf, List<DadosIndicadores> domain);
}
Classe onde estou usando o repository:
@Component
public class ConsultaIndicadoresDataSource implements ConsultaIndicadoresPort {
private final ConsultaIndicadoresRepository repository;
public ConsultaIndicadoresDataSource(ConsultaIndicadoresRepository repository) {
this.repository = repository;
}
@Override
public DadosIndicadores consultar(String numeroDocumento) {
var mapper = DomainToEntityMapper.INSTANCE;
var entity = getDateLastMonth(numeroDocumento);
return mapper.convert(entity);
}
@Override
public List<DadosIndicadores> listar(String numeroDocumento) {
var entity = getDateLastMonth(numeroDocumento);
var mapper = DomainToEntityMapper.INSTANCE;
return repository.findByNumeroCpfAndDomain(numeroDocumento, getPages(numeroDocumento))
.stream()
.map(toDomain -> mapper.convert(entity))
.collect(toList());
}
private DadosIndicadoresEntity getDateLastMonth(String numeroDocumento) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -28);
Date daysBefore = calendar.getTime();
return repository.findByNumeroCpfAndData(numeroDocumento, daysBefore);
}
private List<DadosIndicadores> getPages(String numeroDocumento) {
Pageable page = PageRequest.of(0, 10, Sort.by(numeroDocumento).descending());
var mapper = DomainToEntityMapper.INSTANCE;
Page<DadosIndicadoresEntity> pages = repository.findAll(page);
if (pages.hasContent()) {
pages.getContent();
}
return repository.findAll()
.stream()
.map(mapper::convert)
.collect(toList());
}
}
Entity:
@Entity
@Table(name = "tb_indicadores_investimentos")
public class DadosIndicadoresEntity {
@Column(name = "tipo_view")
private String tipoView;
@Id
@Column(name = "num_cpf", unique = true)
private String numeroCpf;
@Column
private String bank;
@Column
private Date data;
// get set...
Estou usando o map struct para fazer as conversões de objetos.