aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Evgeniy Shishkin2017-03-07 17:12:02 +0300
committerGravatar Evgeniy Shishkin2017-03-07 17:45:48 +0300
commit4b2821008dedf2300d44548f34a53735afc07000 (patch)
tree81d1671015c5df41fe44770ea7c22a1cdef7c833 /juick-server/src/main/java/com/juick/service
parent1a31521dd4e1f7ef96c9d82d69b3d7aa42282eeb (diff)
get user blog with recommendations
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java28
2 files changed, 29 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesService.java b/juick-server/src/main/java/com/juick/service/MessagesService.java
index cad0f860..ad7774b7 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesService.java
@@ -62,6 +62,8 @@ public interface MessagesService {
List<Integer> getUserTag(int uid, int tid, int privacy, int before);
+ List<Integer> getUserBlogWithRecommendations(int uid, int privacy, int before);
+
List<Integer> getUserRecommendations(int uid, int before);
List<Integer> getUserPhotos(int uid, int privacy, int before);
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 495940f6..0a35cee9 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -198,7 +198,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public boolean recommendMessage(final int mid, final int vuid) {
boolean res = getJdbcTemplate().update(
- "INSERT IGNORE INTO favorites(user_id, message_id) VALUES (?, ?)",
+ "INSERT IGNORE INTO favorites(user_id, message_id, ts) VALUES (?, ?, NOW())",
vuid, mid) == 1;
if (res)
@@ -590,6 +590,32 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
+ public List<Integer> getUserBlogWithRecommendations(final int uid, final int privacy, final int before) {
+ SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
+ .addValue("uid", uid)
+ .addValue("privacy", privacy)
+ .addValue("before", before);
+
+ return getNamedParameterJdbcTemplate().queryForList(
+ "SELECT message_id FROM " +
+ "(SELECT message_id FROM favorites " +
+ " WHERE user_id = :uid " +
+ (before > 0 ?
+ " AND message_id < :before " : StringUtils.EMPTY) +
+ " ORDER BY message_id DESC LIMIT 20) as r" +
+ " UNION ALL " +
+ "SELECT message_id FROM " +
+ "(SELECT message_id FROM messages WHERE user_id = :uid" +
+ (before > 0 ?
+ " AND message_id < :before" : StringUtils.EMPTY) +
+ " AND privacy >= :privacy ORDER BY message_id DESC LIMIT 20) as m " +
+ "ORDER BY message_id DESC LIMIT 20",
+ sqlParameterSource,
+ Integer.class);
+ }
+
+ @Transactional(readOnly = true)
+ @Override
public List<Integer> getUserRecommendations(final int uid, final int before) {
SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
.addValue("uid", uid)