aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/MessagesService.java4
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java22
2 files changed, 20 insertions, 6 deletions
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index fb2b3d95..4bcdba46 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -47,9 +47,9 @@ public interface MessagesService {
List<Reaction> listReactions();
- RecommendStatus likeMessage(int mid, int vuid, int reactionId);
+ RecommendStatus likeMessage(int mid, int vuid, Integer reaction);
- RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri);
+ RecommendStatus likeMessage(int mid, int vuid, Integer reaction, String userUri);
boolean canViewThread(int mid, int uid);
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index f45ee351..7951eb42 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -268,15 +268,29 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
@Override
- public RecommendStatus likeMessage(int mid, int vuid, int reactionId) {
- return likeMessage(mid, vuid, reactionId, StringUtils.EMPTY);
+ public RecommendStatus likeMessage(int mid, int vuid, Integer reaction) {
+ return likeMessage(mid, vuid, reaction, StringUtils.EMPTY);
}
@Transactional
@Override
- public RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri) throws IllegalArgumentException {
+ public RecommendStatus likeMessage(int mid, int vuid, Integer reaction, String userUri) throws IllegalArgumentException {
+ if (reaction == null) {
+ SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
+ .addValue("uid", vuid)
+ .addValue("uri", userUri)
+ .addValue("like_id", reaction)
+ .addValue("mid", mid);
+ boolean wasDeleted = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM favorites WHERE user_id=:uid AND message_id=:mid AND like_id=:like_id AND user_uri=:uri", sqlParameterSource) > 0;
+ if (wasDeleted) {
+ return RecommendStatus.Deleted;
+ } else {
+ return RecommendStatus.Error;
+ }
+ }
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid, reactionId, userUri) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid, reaction, userUri) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}