diff options
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/UserServiceImpl.java | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index b5581b76..b15a18e5 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -42,6 +42,7 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Nonnull; +import java.net.URI; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -519,17 +520,23 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override public List<User> getUserReaders(final int uid) { - return getJdbcTemplate().query( - "SELECT users.id, users.nick FROM subscr_users " + - "INNER JOIN users ON subscr_users.suser_id=users.id " + - "WHERE subscr_users.user_id=? ORDER BY users.nick", + return getNamedParameterJdbcTemplate().query( + """ + SELECT users.id, users.nick nick, '' user_uri FROM subscr_users + INNER JOIN users ON subscr_users.suser_id=users.id + WHERE subscr_users.user_id=:user_id + UNION ALL SELECT 0, '', acct user_uri from followers WHERE user_id=:user_id + ORDER BY nick + """, + new MapSqlParameterSource() + .addValue("user_id", uid), (rs, num) -> { User u = new User(); u.setUid(rs.getInt(1)); u.setName(rs.getString(2)); + u.setUri(URI.create(rs.getString(3))); return u; - }, - uid); + }); } @Transactional(readOnly = true) @@ -584,13 +591,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override - public int getStatsMyReaders(final int uid) { - List<Integer> list = getJdbcTemplate().queryForList("SELECT COUNT(*) FROM subscr_users WHERE user_id = ?", Integer.class, uid); - return list.isEmpty() ? 0 : list.get(0); - } - - @Transactional(readOnly = true) - @Override public int getStatsMessages(final int uid) { List<Integer> list = getJdbcTemplate().queryForList("SELECT COUNT(*) FROM messages WHERE user_id = ?", Integer.class, uid); return list.isEmpty() ? 0 : list.get(0); |