aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java17
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();
+ }
}