diff options
Diffstat (limited to 'juick-server-jdbc/src')
-rw-r--r-- | juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java | 8 | ||||
-rw-r--r-- | juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java | 10 |
2 files changed, 15 insertions, 3 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java index 80be200b..8b7ba42e 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java @@ -116,14 +116,16 @@ public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesSe .addValue("uidTo", uidTo); List<com.juick.Message> msgs = getNamedParameterJdbcTemplate().query( - "SELECT user_id, txt,ts FROM pm WHERE (user_id = :uid AND user_id_to = :uidTo) " + "SELECT pm.user_id, pm.txt, pm.ts, users.nick FROM pm INNER JOIN users ON users.id=pm.user_id WHERE (user_id = :uid AND user_id_to = :uidTo) " + "OR (user_id_to = :uid AND user_id = :uidTo) ORDER BY ts DESC LIMIT 20", sqlParameterSource, (rs, rowNum) -> { com.juick.Message msg = new com.juick.Message(); int uuid = rs.getInt(1); - msg.setUser(new User()); - msg.getUser().setUid(uuid); + User user = new User(); + user.setUid(uuid); + user.setName(rs.getString(4)); + msg.setUser(user); msg.setText(rs.getString(2)); msg.setTimestamp(rs.getTimestamp(3).toInstant()); return msg; diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java index 44e46b70..47699dbc 100644 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java @@ -17,6 +17,7 @@ package com.juick.service; +import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.configuration.RepositoryConfiguration; @@ -53,6 +54,8 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { private JdbcTemplate jdbcTemplate; @Inject private CrosspostService crosspostService; + @Inject + private PMQueriesService pmQueriesService; int ugnichId, freefdId, mid; @@ -105,4 +108,11 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { tagService.blacklistTag(freefd, yoTag); assertThat(subscriptionService.getSubscribedUsers(ugnichId, mid).size(), equalTo(1)); } + @Test + public void pmTests() { + pmQueriesService.createPM(freefdId, ugnichId, "hello"); + Message pm = pmQueriesService.getPMMessages(ugnichId, freefdId).get(0); + assertThat(pm.getText(), equalTo("hello")); + assertThat(pm.getUser().getUid(), equalTo(freefdId)); + } } |