diff options
author | Vitaly Takmazov | 2023-02-03 02:13:17 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-02-03 03:39:43 +0300 |
commit | 22aaf28c779725962a3ebec3e689bef35fe05085 (patch) | |
tree | 71e05ad64efc73dff7ba3d6688a567493bc88c09 /src/main/java/com/juick/service | |
parent | d71ce6095b87958d2df4da27b1344ad0e5b77a44 (diff) |
GetTagNoIndex -> tag.isNotIndexed
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r-- | src/main/java/com/juick/service/TagService.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/service/TagServiceImpl.java | 55 |
2 files changed, 24 insertions, 33 deletions
diff --git a/src/main/java/com/juick/service/TagService.java b/src/main/java/com/juick/service/TagService.java index d04aacbc..0701bedf 100644 --- a/src/main/java/com/juick/service/TagService.java +++ b/src/main/java/com/juick/service/TagService.java @@ -38,8 +38,6 @@ public interface TagService { List<Tag> getTags(Stream<String> tags, boolean autoCreate); - boolean getTagNoIndex(int tagId); - int createTag(String name); List<TagStats> getUserTagStats(int uid); diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java index ef5f6e84..0d040273 100644 --- a/src/main/java/com/juick/service/TagServiceImpl.java +++ b/src/main/java/com/juick/service/TagServiceImpl.java @@ -49,17 +49,24 @@ import java.util.stream.Stream; @Repository public class TagServiceImpl extends BaseJdbcService implements TagService { + private class TagMapper implements RowMapper<Tag> { + @Override + public Tag mapRow(ResultSet rs, int rowNum) throws SQLException { + Tag tag = new Tag(rs.getString(3)); + tag.setId(rs.getInt(1)); + tag.setSynonymId(rs.getInt(2)); + tag.setNotIndexed(rs.getInt("noindex") > 0); + tag.setHiddenFromTop(rs.getInt("notop") > 0); + return tag; + } + } + @Transactional(readOnly = true) @Override public Tag getTag(final int tid) { List<Tag> list = getJdbcTemplate().query( - "SELECT synonym_id,name FROM tags WHERE tag_id=?", - (rs, num) -> { - Tag ret = new Tag(rs.getString(2)); - ret.setId(tid); - ret.setSynonymId(rs.getInt(1)); - return ret; - }, + "SELECT tag_id, synonym_id, name, noindex, notop FROM tags WHERE tag_id=?", + new TagMapper(), tid); return list.isEmpty() ? null : list.get(0); @@ -67,25 +74,20 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { @Transactional @Override - public Tag getTag(final String tag, final boolean autoCreate) { - if (StringUtils.isBlank(tag)) + public Tag getTag(final String tagName, final boolean autoCreate) { + if (StringUtils.isBlank(tagName)) return null; List<Tag> list = getJdbcTemplate().query( - "SELECT tag_id, synonym_id, name FROM tags WHERE name = ?", - (rs, rowNum) -> { - Tag ret1 = new Tag(rs.getString(3)); - ret1.setId(rs.getInt(1)); - ret1.setSynonymId(rs.getInt(2)); - return ret1; - }, - tag); + "SELECT tag_id, synonym_id, name, noindex, notop FROM tags WHERE name = ?", + new TagMapper(), + tagName); Tag ret = list.isEmpty() ? null : list.get(0); if (ret == null && autoCreate) { - ret = new Tag(tag); - ret.setId(createTag(tag)); + ret = new Tag(tagName); + ret.setId(createTag(tagName)); } return ret; @@ -98,15 +100,6 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { .toList(); } - @Transactional(readOnly = true) - @Override - public boolean getTagNoIndex(final int tagId) { - List<Boolean> list = getJdbcTemplate().queryForList( - "SELECT noindex FROM tags WHERE tag_id=?", Boolean.class, tagId); - - return !list.isEmpty() && list.get(0); - } - @Transactional @Override public int createTag(final String name) { @@ -162,9 +155,9 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { @Override public List<String> getPopularTags() { return getJdbcTemplate().queryForList(""" - select name from tags where noindex=0 - order by stat_messages desc - """ + limit(20), String.class); + select name from tags where noindex=0 + order by stat_messages desc + """ + limit(20), String.class); } @Transactional(readOnly = true) |