diff options
author | Vitaly Takmazov | 2018-08-14 13:23:53 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-08-14 16:45:12 +0300 |
commit | 2c1bfab10903895ece9644bc095597aaef2a75e8 (patch) | |
tree | c721f8582e2b9f1d91ab88ce7d3dfb6cd7e9d2d5 /juick-server/src/main/java/com/juick/server | |
parent | c0ac4aa5824b45ff9543f60c648625869b11b1a3 (diff) |
Message editing API
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Post.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java index afe9d2d5..b0be50b6 100644 --- a/juick-server/src/main/java/com/juick/server/api/Post.java +++ b/juick-server/src/main/java/com/juick/server/api/Post.java @@ -17,6 +17,7 @@ package com.juick.server.api; +import com.juick.Message; import com.juick.Reaction; import com.juick.Status; import com.juick.User; @@ -202,4 +203,20 @@ public class Post { return recommendStatus == MessagesService.RecommendStatus.Error ? Status.ERROR :Status.OK; } + + @PostMapping("/update") + public CommandResult updateMessage(@RequestParam Integer mid, + @RequestParam(required = false, defaultValue = "0") Integer rid, + @RequestParam String body) { + User visitor = UserUtils.getCurrentUser(); + User author = rid == 0 ? messagesService.getMessageAuthor(mid) : messagesService.getReply(mid, rid).getUser(); + if (visitor.equals(author)) { + if (messagesService.updateMessage(mid, rid, body)) { + Message result = rid == 0 ? messagesService.getMessage(mid) : messagesService.getReply(mid, rid); + return CommandResult.build(result, "Message updated", StringUtils.EMPTY); + } + throw new HttpBadRequestException(); + } + throw new HttpForbiddenException(); + } } |