Add route to fetch post source.

This commit is contained in:
Florian
2018-05-18 22:50:24 +02:00
parent 9fcbf4f576
commit c2c17f9567

View File

@@ -53,12 +53,19 @@ public class PostController {
@GetMapping("/{postKey}") @GetMapping("/{postKey}")
public PostDTO getByKey(@PathVariable("postKey") final String pPostKey, public PostDTO getByKey(@PathVariable("postKey") final String pPostKey,
final HttpServletResponse response) { final HttpServletResponse response) {
final PostDTO result = getByKeyAndSource(pPostKey, response);
result.setText(parserService.parse(result.getText()));
return result;
}
@GetMapping("/{postKey}/source")
public PostDTO getByKeyAndSource(@PathVariable("postKey")final String pPostKey,
final HttpServletResponse response) {
PostDTO result = null; PostDTO result = null;
final Optional<Post> post = postRepository.getByKey(pPostKey); final Optional<Post> post = postRepository.getByKey(pPostKey);
if(post.isPresent()) { if(post.isPresent()) {
result = new PostDTO(post.get()); result = new PostDTO(post.get());
result.setText(parserService.parse(result.getText()));
} else { } else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
} }