diff options
author | 2018-04-18 15:57:53 +0300 | |
---|---|---|
committer | 2018-04-20 11:03:47 +0300 | |
commit | 842e903d5b987dd23e82a423bddae75acdea0c9c (patch) | |
tree | 59eabfb9969b6cbe00703674f8d3ddb7d2e029e0 /juick-server/src/main/java/com/juick/server/api/Post.java | |
parent | ef1c674b0dc1979e46e970ad67ccc7a9bb67b001 (diff) |
Like -> Reaction
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api/Post.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Post.java | 27 |
1 files changed, 26 insertions, 1 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 9dd42db0..5a027ece 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 @@ -22,8 +22,8 @@ import com.juick.User; import com.juick.server.CommandsManager; import com.juick.server.EmailManager; import com.juick.server.XMPPConnection; -import com.juick.server.util.*; import com.juick.server.helpers.CommandResult; +import com.juick.server.util.*; import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; import com.juick.service.UserService; @@ -44,6 +44,7 @@ import javax.inject.Inject; import javax.mail.Session; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; +import javax.validation.constraints.NotNull; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -235,6 +236,7 @@ public class Post { throw new HttpForbiddenException(); } } + @PostMapping("/like") @ResponseStatus(value = HttpStatus.OK) public Status doPostRecomm(@RequestParam Integer mid) throws Exception { @@ -253,4 +255,27 @@ public class Post { URI.create(StringUtils.EMPTY)); return Status.getStatus(status.getText()); } + + @PostMapping("/react") + @ResponseStatus(value = HttpStatus.OK) + public Status doPostReact(@RequestParam Integer mid,@RequestParam @NotNull int reactionId){ + + logger.info("got reaction with type: {}", reactionId); + com.juick.User visitor = UserUtils.getCurrentUser(); + if (visitor.getUid() == 0) { + throw new HttpForbiddenException(); + } + com.juick.Message msg = messagesService.getMessage(mid); + if (msg == null) { + throw new HttpNotFoundException(); + } + if (msg.getUser().getUid() == visitor.getUid()) { + throw new HttpForbiddenException(); + } + + MessagesService.RecommendStatus recommendStatus = messagesService.likeMessage(mid,msg.getUser().getUid(), + reactionId); + + return recommendStatus == MessagesService.RecommendStatus.Error ? Status.ERROR :Status.OK; + } } |