findById
Controller
Service
Atualizado
Controller
@GetMapping(value = "/{id}")
public PostDTO findById(@PathVariable String id) {
return postService.findById(id);
}
Service
public PostDTO findById(String id) {
Post post = postRepository.findById(id)
.orElseThrow(() -> new ResourceNotFound("Post not found"));
return new PostDTO(post);
}
private Post getEntityById(String id) {
Optional<Post> post = postRepository.findById(id);
return post.orElseThrow(() -> new ResourceNotFound("Objeto não encontrado."));
}
Atualizado