diff options
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Messages.java | 1 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Post.java | 27 |
2 files changed, 27 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 8142a179..c6600e2b 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 @@ -90,6 +90,7 @@ public class Messages { @RequestParam(required = false) String popular, @RequestParam(required = false) String media, @RequestParam(required = false) String tag) { + User visitor = UserUtils.getCurrentUser(); int vuid = visitor.getUid(); 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; + } } |