aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-20 11:22:21 +0300
committerGravatar Vitaly Takmazov2018-04-20 11:22:21 +0300
commitdb14962b7171eb0e713da54eecb032331d551d66 (patch)
tree85d24b6a9d6d57759a2bc944bdf439614c2b1662
parent842e903d5b987dd23e82a423bddae75acdea0c9c (diff)
server: /reactions list
-rw-r--r--juick-common/src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java10
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java11
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java9
4 files changed, 27 insertions, 5 deletions
diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java
index 853e4271..9af000f8 100644
--- a/juick-common/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-common/src/main/java/com/juick/service/MessagesService.java
@@ -44,6 +44,8 @@ public interface MessagesService {
RecommendStatus recommendMessage(int mid, int vuid);
+ List<Reaction> listReactions();
+
RecommendStatus likeMessage(int mid, int vuid, int reactionId);
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 362a918c..7816ef67 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
@@ -240,6 +240,16 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
@Override
+ public List<Reaction> listReactions() {
+ return jdbcTemplate.query("SELECT like_id, description FROM reactions", (RowMapper<Reaction>) (rs, rowNum) -> {
+ Reaction reaction = new Reaction(rs.getInt("like_id"));
+ reaction.setDescription(rs.getString("description"));
+ return reaction;
+ });
+ }
+
+ @Transactional
+ @Override
public RecommendStatus likeMessage(int mid, int vuid, int reactionId) throws IllegalArgumentException {
if(reactionId == Reaction.LIKE) throw new IllegalArgumentException("this reaction type does not support here");
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 5a027ece..2e1ca6d7 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
@@ -17,6 +17,7 @@
package com.juick.server.api;
+import com.juick.Reaction;
import com.juick.Status;
import com.juick.User;
import com.juick.server.CommandsManager;
@@ -52,9 +53,7 @@ import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
-import java.util.Properties;
-import java.util.Scanner;
-import java.util.UUID;
+import java.util.*;
/**
* Created by vt on 24/11/2016.
@@ -256,6 +255,12 @@ public class Post {
return Status.getStatus(status.getText());
}
+ @GetMapping("/reactions")
+ @ResponseStatus(value = HttpStatus.OK)
+ public List<Reaction> reactionsList() {
+ return messagesService.listReactions();
+ }
+
@PostMapping("/react")
@ResponseStatus(value = HttpStatus.OK)
public Status doPostReact(@RequestParam Integer mid,@RequestParam @NotNull int reactionId){
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 6b31906d..575bc7d1 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
@@ -444,9 +444,14 @@ public class ServerTests {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect((jsonPath("$[0].reactions[?(@.id == 3)].count",
- Matchers.is(Collections.singletonList(1)))))
+ is(Collections.singletonList(1)))))
.andExpect((jsonPath("$[0].reactions[?(@.id == 2)].count",
- Matchers.is(Collections.singletonList(2)))));
+ is(Collections.singletonList(2)))));
+
+ mockMvc.perform(get("/reactions?hash=" + userIdHash))
+ .andExpect(status().isOk())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(jsonPath("$.length()", is(7)));
}
@Test