diff --git a/src/main/java/ru/org/linux/topic/TopicPrepareService.java b/src/main/java/ru/org/linux/topic/TopicPrepareService.java index 9d48afa823..f22e59e5f2 100644 --- a/src/main/java/ru/org/linux/topic/TopicPrepareService.java +++ b/src/main/java/ru/org/linux/topic/TopicPrepareService.java @@ -420,7 +420,7 @@ public TopicMenu getTopicMenu( int favsId; boolean deletable; - List topicStats = memoriesDao.getTopicStats(message.getMessage().getId()); + MemoriesStat topicStats = memoriesDao.getTopicStats(message.getMessage().getId()); if (currentUser!=null) { resolvable = (currentUser.isModerator() || (message.getAuthor().getId()==currentUser.getId())) && @@ -453,8 +453,8 @@ public TopicMenu getTopicMenu( resolvable, memoriesId, favsId, - topicStats.get(0), - topicStats.get(1), + topicStats.watchCount(), + topicStats.favsCount(), topicPermissionService.isCommentsAllowed(message.getGroup(), message.getMessage(), currentUser), deletable, userpic diff --git a/src/main/java/ru/org/linux/user/MemoriesController.java b/src/main/java/ru/org/linux/user/MemoriesController.java index 1102ae1725..1942be4c94 100644 --- a/src/main/java/ru/org/linux/user/MemoriesController.java +++ b/src/main/java/ru/org/linux/user/MemoriesController.java @@ -62,7 +62,7 @@ public Map add( int id = memoriesDao.addToMemories(user, topic, watch); - int count = memoriesDao.getTopicStats(msgid).get(watch?0:1); + int count = watch?memoriesDao.getTopicStats(msgid).watchCount():memoriesDao.getTopicStats(msgid).favsCount(); return ImmutableMap.of("id", id, "count", count); } @@ -92,7 +92,7 @@ public int remove( memoriesDao.delete(id); - return memoriesDao.getTopicStats(m.getTopic()).get(m.isWatch()?0:1); + return m.isWatch()?memoriesDao.getTopicStats(m.getTopic()).watchCount():memoriesDao.getTopicStats(m.getTopic()).favsCount(); } else { return -1; } diff --git a/src/main/java/ru/org/linux/user/MemoriesDao.java b/src/main/java/ru/org/linux/user/MemoriesDao.java index 2549d7658a..a162836a7a 100644 --- a/src/main/java/ru/org/linux/user/MemoriesDao.java +++ b/src/main/java/ru/org/linux/user/MemoriesDao.java @@ -68,10 +68,6 @@ private int doAddToMemories(User user, Topic topic, boolean watch) { /** * Get memories id or 0 if not in memories - * - * @param user - * @param topic - * @return */ public int getId(User user, Topic topic, boolean watch) { List res = jdbcTemplate.queryForList( @@ -91,9 +87,8 @@ public int getId(User user, Topic topic, boolean watch) { /** * get number of memories/favs for topic - * @return list(0) - memories, list(1) - favs */ - public List getTopicStats(int topic) { + public MemoriesStat getTopicStats(int topic) { final List res = Lists.newArrayList(0, 0); jdbcTemplate.query( @@ -111,8 +106,7 @@ public void processRow(ResultSet rs) throws SQLException { topic ); - return res; - + return new MemoriesStat(res.get(0), res.get(1)); } public MemoriesListItem getMemoriesListItem(int id) { @@ -141,7 +135,6 @@ public boolean isFavPresetForUser(User user) { return checkMemoriesPresent(user, false); } - private boolean checkMemoriesPresent(User user, boolean watch) { List present = jdbcTemplate.queryForList( "select memories.id from memories join topics on memories.topic=topics.id where memories.userid=? and watch=? and not deleted limit 1;", @@ -160,21 +153,7 @@ private boolean checkMemoriesPresent(User user, boolean watch) { */ public int getWatchCountForUser(User user) { List ret = jdbcTemplate.queryForList("select count(id) from memories where userid=? and watch='t'", Integer.class, user.getId()); - if(ret == null || ret.isEmpty()) { - return 0; - } else { - return ret.get(0); - } - } - - /** - * get number of favorite memories for user - * @param user user - * @return count memories - */ - public int getFavCountForUser(User user) { - List ret = jdbcTemplate.queryForList("select count(id) from memories where userid=? and watch='f'", Integer.class, user.getId()); - if(ret == null || ret.size() == 0) { + if(ret.isEmpty()) { return 0; } else { return ret.get(0); diff --git a/src/main/scala/ru/org/linux/user/MemoriesStat.scala b/src/main/scala/ru/org/linux/user/MemoriesStat.scala new file mode 100644 index 0000000000..919b88c013 --- /dev/null +++ b/src/main/scala/ru/org/linux/user/MemoriesStat.scala @@ -0,0 +1,3 @@ +package ru.org.linux.user + +case class MemoriesStat(watchCount:Int, favsCount:Int)