Why in the service and in the controller do the objects point to the same function? I'll detail:
Repository:
@RepositoryRestResource(exported = false)
public interface AtividadeRepository extends CrudRepository<Atividade, Integer> {
Atividade findByNome(String nome); //até aqui tudo bem.
}
service:
public Iterable<Atividade> findAll() {
return atividadeRepository.findAll();
}
//Retorna todas as atividades, até aqui tudo bem.
Controller:
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public @ResponseBody ResponseEntity<Iterable<Atividade>> listAll() {
Iterable<Atividade> atividades;
atividades = atividadeService.findAll();
return new ResponseEntity<Iterable<Atividade>>(atividades, HttpStatus.OK);
}
Why in addition to using the same method, does it also have the return?
Can not the controller get the object from the repository and send it to the view instead of the "search" and return? Or the line:
return new ResponseEntity<Iterable<Atividade>>(atividades, HttpStatus.OK);
Does it only return the status?
I know you have the question of reusing code, but doing the same search, I find it redundant.
Or am I totally out of the way?