aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-20 11:27:46 +0300
committerGravatar Vitaly Takmazov2018-04-20 14:29:02 +0300
commit0f0009ff1c86fd8ae3af122851034eac21645e11 (patch)
tree6f9d3362f75f2e8528512e8f2f5b0eb249910531
parentdb14962b7171eb0e713da54eecb032331d551d66 (diff)
server: fix compatibility with likes
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java16
-rw-r--r--juick-server/build.gradle2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java2
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java4
4 files changed, 11 insertions, 13 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index 7816ef67..d339d229 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -337,7 +337,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "INNER JOIN messages_txt AS txt "
+ "ON messages.message_id = txt.message_id "
+ "LEFT JOIN favorites "
- + "ON messages.message_id = favorites.message_id "
+ + "ON messages.message_id = favorites.message_id AND favorites.like_id=1 "
+ "WHERE messages.message_id = ? "
+ "GROUP BY mid, rid, replyto, uid, nick, banned, ago, messages.ts, readonly, "
+ "privacy, replies, attach, place_id, lat, lon, tags, repliesby, q",
@@ -422,7 +422,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
public List<String> getMessageRecommendations(final int mid) {
return getJdbcTemplate().queryForList(
"SELECT users.nick FROM favorites INNER JOIN users " +
- "ON (favorites.message_id = ? AND favorites.user_id = users.id)",
+ "ON (favorites.message_id = ? AND favorites.user_id = users.id) WHERE favorites.like_id=1",
new Object[]{mid},
String.class);
}
@@ -806,8 +806,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public Map<Integer,Set<Reaction>> updateReactionsFor(final List<Integer> mids) {
- return getNamedParameterJdbcTemplate().query("select f.message_id as mid, f.like_id as lid, " +
- "r.description as desc, count(f.like_id) as count" +
+ return getNamedParameterJdbcTemplate().query("select f.message_id as mid, f.like_id as lid," +
+ " r.description as descr, count(f.like_id) as cnt" +
" from favorites f LEFT JOIN reactions r ON f.like_id = r.like_id " +
" where f.message_id IN (:mids) " +
" group by f.message_id, f.like_id", new MapSqlParameterSource("mids", mids), (ResultSet rs) -> {
@@ -815,10 +815,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
while (rs.next()) {
- int messageId = rs.getInt("message_id");
- int likeId = rs.getInt("like_id");
- int count = rs.getInt("count");
- String description = rs.getString("description");
+ int messageId = rs.getInt("mid");
+ int likeId = rs.getInt("lid");
+ int count = rs.getInt("cnt");
+ String description = rs.getString("descr");
Reaction reaction = new Reaction(likeId);
reaction.setCount(count);
reaction.setDescription(description);
diff --git a/juick-server/build.gradle b/juick-server/build.gradle
index c1a930b3..d496ec69 100644
--- a/juick-server/build.gradle
+++ b/juick-server/build.gradle
@@ -30,4 +30,4 @@ dependencies {
bootJar {
launchScript()
-} \ No newline at end of file
+}
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 2e1ca6d7..3b022aae 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
@@ -278,7 +278,7 @@ public class Post {
throw new HttpForbiddenException();
}
- MessagesService.RecommendStatus recommendStatus = messagesService.likeMessage(mid,msg.getUser().getUid(),
+ MessagesService.RecommendStatus recommendStatus = messagesService.likeMessage(mid,visitor.getUid(),
reactionId);
return recommendStatus == MessagesService.RecommendStatus.Error ? Status.ERROR :Status.OK;
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 575bc7d1..0902eb8f 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -813,15 +813,13 @@ public class ServerTests {
public void likesTests() throws Exception{
int user_id = userService.createUser("dsds", "secret");
String freefdHash = userService.getHashByUID(freefd.getUid());
- System.out.println("user_id"+ user_id);
- String userIdHash = userService.getHashByUID(user_id);
int mid1 = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=2"))
.andExpect(status().isOk());
Message msg4 = messagesService.getMessage(mid1);
- System.out.println("msg4"+msg4);
+ assertThat(msg4.getLikes(), is(0));
Assert.assertEquals(1, msg4.getReactions().stream().filter(r -> r.getId() == 2)
.findFirst().orElseThrow(IllegalStateException::new).getCount());
}