Last active
November 14, 2018 01:17
-
-
Save rponte/e1100e2c056adcd2d3a4de66c450bca2 to your computer and use it in GitHub Desktop.
Desenhando modelo com repositórios e segregação de interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) { | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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