From 30ef0800930e668035eb34013714c08d707f86a0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 28 Jun 2018 15:49:57 +0300 Subject: delete messages api --- .../src/main/java/com/juick/server/api/Messages.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'juick-server/src/main/java/com/juick') 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> 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 getDiscussions( @RequestParam(required = false, defaultValue = "0") Long to) { -- cgit v1.2.3