aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server-jdbc/src')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java8
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java34
2 files changed, 31 insertions, 11 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 caffda14..3533d701 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
@@ -445,7 +445,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
- public List<Integer> getMyFeed(final int uid, final int before) {
+ public List<Integer> getMyFeed(final int uid, final int before, boolean recommended) {
SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
.addValue("uid", uid)
.addValue("before", before);
@@ -462,6 +462,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
" (SELECT message_id FROM messages WHERE user_id=:uid " +
(before > 0 ?
" AND message_id < :before " : StringUtils.EMPTY) +
+ (recommended ?
+ ") UNION " +
+ " (SELECT f.message_id as message_id FROM favorites f WHERE " +
+ "EXISTS (SELECT 1 FROM subscr_users s WHERE s.suser_id = :uid and f.user_id = s.user_id)" +
+ (before > 0 ?
+ " AND f.message_id < :before " : StringUtils.EMPTY) : StringUtils.EMPTY) +
") ORDER BY message_id DESC LIMIT 20",
sqlParameterSource,
Integer.class);
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 fae938cc..64de9424 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
@@ -18,11 +18,13 @@
package com.juick.service;
import com.juick.configuration.RepositoryConfiguration;
+import com.juick.server.helpers.AnonymousUser;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.inject.Inject;
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@@ -36,20 +38,32 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests {
private MessagesService messagesService;
@Inject
private UserService userService;
+ @Inject
+ private SubscriptionService subscriptionService;
+
+ int ugnichId, freefdId, mid;
@Test
public void getMyFeed() {
- messagesService.getMyFeed(1, 1000000);
- }
- @Test
- public void likesCountShouldMatch() {
- int uid = userService.createUser("ugnich", "secret");
- int mid = messagesService.createMessage(uid, "test", null, null);
- int mid2 = messagesService.createMessage(uid, "test2", null, null);
- assertThat(messagesService.recommendMessage(mid, uid), equalTo(true));
+ ugnichId = userService.createUser("ugnich", "secret");
+ freefdId = userService.createUser("freefd", "secret");
+ mid = messagesService.createMessage(ugnichId, "test", null, null);
+ int mid2 = messagesService.createMessage(ugnichId, "test2", null, null);
+ subscriptionService.subscribeUser(userService.getUserByUID(freefdId).orElse(AnonymousUser.INSTANCE),
+ userService.getUserByUID(ugnichId).orElse(AnonymousUser.INSTANCE));
+ List<Integer> freefdFeed = messagesService.getMyFeed(freefdId, 0, false);
+ assertThat(freefdFeed.size(), equalTo(2));
+ int tonyaid = userService.createUser("Tonya", "secret");
+ int mid3 = messagesService.createMessage(tonyaid, "test3", null, null);
+ messagesService.recommendMessage(mid3, ugnichId);
+ assertThat(messagesService.getMyFeed(freefdId, 0, false).size(), equalTo(2));
+ assertThat(messagesService.getMyFeed(freefdId, 0, true).size(), equalTo(3));
+ assertThat(messagesService.getMyFeed(freefdId, mid2, true).size(), equalTo(1));
+ assertThat(messagesService.getMyFeed(freefdId, mid, false).size(), equalTo(0));
+ assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(true));
assertThat(messagesService.getMessage(mid).getLikes(), equalTo(1));
- assertThat(messagesService.recommendMessage(mid, uid), equalTo(false));
+ assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(false));
assertThat(messagesService.getMessage(mid).getLikes(), equalTo(0));
- assertThat(messagesService.getAll(uid, 0).size(), equalTo(2));
+ assertThat(messagesService.getAll(ugnichId, 0).size(), equalTo(3));
}
}