Add create-update post component.

This commit is contained in:
2019-02-11 21:05:40 +01:00
parent b3603e242f
commit dbd07a3362
11 changed files with 794 additions and 16 deletions
@@ -120,36 +120,32 @@ public class PostController {
@JsonView(View.PostDTO.class)
@PostMapping("/preview")
public PostDTO preview(@RequestBody final PostDTO pPost) {
final PostDTO result = new PostDTO();
result.setTitle(pPost.getTitle());
result.setImage(pPost.getImage() == null || "".equals(pPost.getImage())
public Post preview(@RequestBody final Post pPost) {
pPost.setImage(pPost.getImage() == null || "".equals(pPost.getImage())
? "https://news-cdn.softpedia.com/images/news2/this-is-the-default-wallpaper-of-the-gnome-3-20-desktop-environment-500743-2.jpg"
: pPost.getImage());
result.setDescription(pPost.getDescription());
result.setText(parserService.parse(pPost.getText()));
pPost.setText(parserService.parse(pPost.getText()));
return result;
return pPost;
}
@JsonView(View.PostDTO.class)
@PostMapping("/")
public PostDTO insert(@RequestBody final PostDTO pPost, final HttpServletRequest pRequest,
public Post insert(@RequestBody final PostDTO pPost, final HttpServletRequest pRequest,
final HttpServletResponse pResponse, final Principal pPrincipal) {
PostDTO result = null;
Post result = null;
Optional<Post> postCreated = postService.insert(pPost, pRequest, pResponse, pPrincipal);
if(postCreated.isPresent()) {
result = new PostDTO(postCreated.get());
result = postCreated.get();
}
return result;
}
@PutMapping("/")
public void update(@RequestBody final PostDTO pPost, final HttpServletRequest pRequest,
public void update(@RequestBody final Post pPost, final HttpServletRequest pRequest,
final HttpServletResponse pResponse, final Principal pPrincipal) throws IOException {
postService.update(pPost, pRequest, pResponse, pPrincipal);
}