aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-28 15:49:57 +0300
committerGravatar Vitaly Takmazov2018-06-28 15:49:57 +0300
commit30ef0800930e668035eb34013714c08d707f86a0 (patch)
treec78387c83327095cda0a6e973209f9fc510bb21e /juick-server/src/main/java/com/juick/server
parent93ad3ee53241b07a08334c4c70f8965cbdc856d5 (diff)
delete messages api
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
index 69cf828c..1c3062af 100644
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ b/juick-server/src/main/java/com/juick/server/api/Messages.java
@@ -22,6 +22,7 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.server.Utils;
import com.juick.server.component.MessageReadEvent;
+import com.juick.server.helpers.CommandResult;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.UserUtils;
import com.juick.service.MessagesService;
@@ -80,7 +81,7 @@ public class Messages {
return FORBIDDEN;
}
- @RequestMapping("/messages")
+ @GetMapping("/messages")
public ResponseEntity<List<com.juick.Message>> getMessages(
@RequestParam(required = false) String uname,
@RequestParam(name = "before_mid", defaultValue = "0") Integer before,
@@ -138,6 +139,19 @@ public class Messages {
}
return ResponseEntity.ok(messagesService.getMessages(mids));
}
+ @DeleteMapping("/messages")
+ public CommandResult deleteMessage(@RequestParam int mid, @RequestParam(required = false, defaultValue = "0") int rid) {
+ User visitor = UserUtils.getCurrentUser();
+ if (rid > 0) {
+ if (messagesService.deleteReply(visitor.getUid(), mid, rid)) {
+ return CommandResult.fromString("Reply deleted");
+ }
+ }
+ if (messagesService.deleteMessage(visitor.getUid(), mid)) {
+ return CommandResult.fromString("Message deleted");
+ }
+ throw new HttpBadRequestException();
+ }
@GetMapping("/messages/discussions")
public List<Message> getDiscussions(
@RequestParam(required = false, defaultValue = "0") Long to) {