Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active November 14, 2018 01:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rponte/e1100e2c056adcd2d3a4de66c450bca2 to your computer and use it in GitHub Desktop.
Save rponte/e1100e2c056adcd2d3a4de66c450bca2 to your computer and use it in GitHub Desktop.
Desenhando modelo com repositórios e segregação de interfaces
@Entity
@EntityListeners(RepositoryAwareListener.class) // https://domineospring.wordpress.com/2018/02/06/repositorios-e-models/
public class Cliente {
@Autowired
private transient OrcamentosAnuais orcamentos;
// atributos da entidade
public List<Orcamento> getOrcamentosDoAnoCorrente() {
int ano = 2018;
return this.orcamentos.aPartirDoAno(this, ano);
}
}
@Repository
public class ClienteRepository implements CrudRepository<Cliente>, OrcamentosAnuais {
public Cliente findById(Long id) { ... }
public void remove(Long id) { ... }
// outros métodos de crud
/**
* Comportamento necessário no modelo
*/
public List<Orcamento> aPartirDoAno(Cliente solicitante, int ano) {
// ...
}
}
/**
* Representa um conceito do domínio - o nome da interface é MUITO importante aqui
*/
public interface OrcamentosAnuais {
public List<Orcamento> aPartirDoAno(Cliente solicitante, int ano);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment