aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-08 13:02:06 +0300
committerGravatar Vitaly Takmazov2018-10-08 13:02:06 +0300
commit2ae9bb8e420d2c68fef9215fbed6d15c3a434b2e (patch)
tree75851e8d1233b4298fcfbea7a3c5dd94701799c1 /juick-server/src/main/java/com/juick/service
parent5e3bb9067b3052c0805b7b1d59215f2bd4b73905 (diff)
user_uri in favorites
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java27
1 files changed, 21 insertions, 6 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index 62cdff0c..1d52e48a 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -233,14 +233,19 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional
@Override
- public RecommendStatus recommendMessage(final int mid, final int vuid) {
- int wasDeleted = getJdbcTemplate()
- .update("DELETE FROM favorites WHERE user_id=? AND message_id=? and like_id=?", vuid, mid, Reaction.LIKE);
+ public RecommendStatus recommendMessage(final int mid, final int vuid, final String userUri) {
+ SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
+ .addValue("uid", vuid)
+ .addValue("uri", userUri)
+ .addValue("like_id", Reaction.LIKE)
+ .addValue("mid", mid);
+ int wasDeleted = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM favorites WHERE user_id=:uid AND message_id=:mid AND like_id=:like_id AND user_uri=:uri", sqlParameterSource);
if (wasDeleted > 0) {
return RecommendStatus.Deleted;
} else {
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts, like_id ) VALUES (?, ?, NOW(), ?)", vuid, mid,Reaction.LIKE) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid,Reaction.LIKE, userUri) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}
@@ -249,6 +254,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
@Override
+ public RecommendStatus recommendMessage(int mid, int vuid) {
+ return recommendMessage(mid, vuid, StringUtils.EMPTY);
+ }
+
+ @Override
public List<Reaction> listReactions() {
return jdbcTemplate.query("SELECT like_id, description FROM reactions", (rs, rowNum) -> {
Reaction reaction = new Reaction(rs.getInt("like_id"));
@@ -257,11 +267,16 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
});
}
+ @Override
+ public RecommendStatus likeMessage(int mid, int vuid, int reactionId) {
+ return likeMessage(mid, vuid, reactionId, StringUtils.EMPTY);
+ }
+
@Transactional
@Override
- public RecommendStatus likeMessage(int mid, int vuid, int reactionId) throws IllegalArgumentException {
+ public RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri) throws IllegalArgumentException {
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts, like_id ) VALUES (?, ?, NOW(), ?)", vuid, mid, reactionId) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid, reactionId, userUri) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}