diff options
author | Vitaly Takmazov | 2018-07-15 11:43:36 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-07-15 11:43:36 +0300 |
commit | 3870fd009e13d728a343d2ebe79c4f6cd113f2ab (patch) | |
tree | 8718ba7d045a9ac7a337244373fbbd1af76b4966 | |
parent | 3936bb230a856c12a0afbab3fb1baa331beee337 (diff) |
Api: read and readers in /me
5 files changed, 33 insertions, 43 deletions
diff --git a/juick-common/src/main/java/com/juick/User.java b/juick-common/src/main/java/com/juick/User.java index 5edfe782..3b74f31c 100644 --- a/juick-common/src/main/java/com/juick/User.java +++ b/juick-common/src/main/java/com/juick/User.java @@ -46,6 +46,8 @@ public class User { private String credentials; private String lang; private List<ExternalToken> tokens; + private List<User> read; + private List<User> readers; public User() { tokens = new ArrayList<>(); @@ -182,4 +184,19 @@ public class User { public void setTokens(List<ExternalToken> tokens) { this.tokens = tokens; } + + public List<User> getRead() { + return read; + } + public List<User> getReaders() { + return readers; + } + + public void setRead(List<User> read) { + this.read = read; + } + + public void setReaders(List<User> readers) { + this.readers = readers; + } } diff --git a/juick-common/src/main/java/com/juick/service/UserService.java b/juick-common/src/main/java/com/juick/service/UserService.java index 858a47be..df62f0ef 100644 --- a/juick-common/src/main/java/com/juick/service/UserService.java +++ b/juick-common/src/main/java/com/juick/service/UserService.java @@ -69,8 +69,6 @@ public interface UserService { String getHashByUID(int uid); - int getUIDByHttpAuth(String header); - int checkPassword(String username, String password); boolean updatePassword(User user, String newPassword); @@ -97,8 +95,6 @@ public interface UserService { boolean isSubscribed(int uid, int check); - List<Integer> getUserRead(int uid); - List<com.juick.User> getUserReadLeastPopular(int uid, int cnt); List<User> getUserReaders(int uid); @@ -109,8 +105,6 @@ public interface UserService { boolean linkTwitterAccount(User user, String accessToken, String accessTokenSecret, String screenName); - int getStatsIRead(int uid); - int getStatsMyReaders(int uid); int getStatsMessages(int uid); diff --git a/juick-server/src/main/java/com/juick/server/api/Users.java b/juick-server/src/main/java/com/juick/server/api/Users.java index a7ea7ea0..9a2b25d7 100644 --- a/juick-server/src/main/java/com/juick/server/api/Users.java +++ b/juick-server/src/main/java/com/juick/server/api/Users.java @@ -78,6 +78,8 @@ public class Users { me.setName(visitor.getName()); me.setAuthHash(getAuthToken()); me.setUnreadCount(messagesService.getUnread(visitor).size()); + me.setRead(userService.getUserFriends(visitor.getUid())); + me.setReaders(userService.getUserReaders(visitor.getUid())); return me; } @@ -101,13 +103,7 @@ public class Users { } if (uid > 0) { - List<Integer> uids = userService.getUserRead(uid); - if (uids.size() > 0) { - List<com.juick.User> users = userService.getUsersByID(uids); - if (users.size() > 0) { - return users; - } - } + return userService.getUserFriends(uid); } throw new HttpNotFoundException(); } diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java index 050fc281..2de3dfc6 100644 --- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java @@ -307,18 +307,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return list.get(0); } - @Override - public int getUIDByHttpAuth(String auth) { - if (auth != null && auth.length() > 8 && auth.startsWith("Basic ")) { - Base64.Decoder dec = Base64.getDecoder(); - String loginpassw[] = new String(dec.decode(auth.substring(6))).split(":", 2); - if (loginpassw.length == 2 && loginpassw[0].length() > 1 && loginpassw[0].length() < 16 && loginpassw[0].matches("[a-zA-Z0-9\\-]+") && !loginpassw[1].isEmpty()) { - return checkPassword(loginpassw[0], loginpassw[1]); - } - } - return 0; - } - @Transactional(readOnly = true) @Override public int checkPassword(final String username, final String password) { @@ -499,13 +487,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override - public List<Integer> getUserRead(final int uid) { - return getJdbcTemplate().queryForList( - "SELECT user_id FROM subscr_users WHERE suser_id=?", Integer.class, uid); - } - - @Transactional(readOnly = true) - @Override public List<com.juick.User> getUserReadLeastPopular(final int uid, final int cnt) { return getJdbcTemplate().query( "SELECT users.id,users.nick FROM (subscr_users " + @@ -586,14 +567,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override - public int getStatsIRead(final int uid) { - List<Integer> list = getJdbcTemplate().queryForList( - "SELECT COUNT(*) FROM subscr_users WHERE suser_id = ?", Integer.class, uid); - return list.isEmpty() ? 0 : list.get(0); - } - - @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); 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 3fc56af7..3ac4ff82 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 @@ -230,6 +230,8 @@ public class ServerTests { assertThat(telegramService.getTelegramIdentifiers(subscribers2).size(), equalTo(0)); tagService.blacklistTag(freefd, yoTag); assertThat(subscriptionService.getSubscribedUsers(ugnich.getUid(), mid).size(), equalTo(1)); + subscriptionService.unSubscribeUser(freefd, ugnich); + assertThat(subscriptionService.getSubscribedUsers(ugnich.getUid(), mid).size(), equalTo(0)); } @Test public void pmTests() { @@ -1042,11 +1044,19 @@ public class ServerTests { assertThat(attachment.getWidth(), is(1)); } @Test - public void meContainsHash() throws Exception { + public void meContainsAllInfo() throws Exception { + jdbcTemplate.update("DELETE FROM subscr_users"); + assertThat(userService.getUserReaders(ugnich.getUid()).size(), is(0)); + assertThat(userService.getUserFriends(ugnich.getUid()).size(), is(0)); + commandsManager.processCommand(freefd, "S @ugnich", emptyUri); + commandsManager.processCommand(ugnich, "S @freefd", emptyUri); + assertThat(userService.getUserReaders(ugnich.getUid()).size(), is(1)); String hash = userService.getHashByUID(ugnich.getUid()); mockMvc.perform(get("/me") - .with(httpBasic(ugnichName, ugnichPassword))) - .andExpect(jsonPath("$.hash", is(hash))); + .with(httpBasic(ugnichName, ugnichPassword))) + .andExpect(jsonPath("$.hash", is(hash))) + .andExpect(jsonPath("$.readers.length()", is(1))) + .andExpect(jsonPath("$.read.length()", is(1))); } @Test public void feedsShouldNotContainBannedUsers() throws Exception { |