X Tutup
Skip to content

Commit 7ec7900

Browse files
committed
fix tag counting
1 parent 19fcbea commit 7ec7900

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/main/java/com/raysmond/blog/repositories/PostRepository.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public interface PostRepository extends JpaRepository<Post, Long> {
2929
@Query("SELECT p FROM Post p INNER JOIN p.tags t WHERE t.name = :tag")
3030
Page<Post> findByTag(@Param("tag") String tag, Pageable pageable);
3131

32-
@Query("SELECT t.name, count(p) as count from Post p INNER JOIN p.tags t GROUP BY t.id")
33-
List<Map<String, Long>> countPostsByTags();
32+
@Query("SELECT t.name, count(p) as tag_count from Post p " +
33+
"INNER JOIN p.tags t " +
34+
"WHERE p.postStatus = :status " +
35+
"GROUP BY t.id " +
36+
"ORDER BY tag_count DESC")
37+
List<Map<String, Long>> countPostsByTags(@Param("status") PostStatus status);
3438
}
3539

src/main/java/com/raysmond/blog/services/AppSetting.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ public class AppSetting {
1717
private String siteName = "SpringBlog";
1818
private String siteSlogan = "An interesting place to discover";
1919
private Integer pageSize = 5;
20-
// other settings
2120

2221
public static final String SITE_NAME = "site_name";
2322
public static final String SITE_SLOGAN = "site_slogan";
2423
public static final String PAGE_SIZE = "page_size";
25-
// other setting keys
2624

2725
@Autowired
2826
public AppSetting(SettingService settingService){

src/main/java/com/raysmond/blog/services/PostService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ public Page<Post> findPostsByTag(String tagName, int page, int pageSize){
207207
public List<Map<String, Long>> countPostsByTags(){
208208
logger.debug("Count posts group by tags.");
209209

210-
return postRepository.countPostsByTags();
210+
return postRepository.countPostsByTags(PostStatus.PUBLISHED);
211211
}
212212
}

src/main/java/com/raysmond/blog/services/SettingService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Raysmond<i@raysmond.com>
77
*/
88
public interface SettingService {
9-
public Serializable get(String key);
10-
public Serializable get(String key, Serializable defaultValue);
11-
public void put(String key, Serializable value);
9+
Serializable get(String key);
10+
Serializable get(String key, Serializable defaultValue);
11+
void put(String key, Serializable value);
1212
}

src/main/java/com/raysmond/blog/services/TagService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public void deleteTag(Tag tag){
5757

5858
@Cacheable(value = CACHE_NAME_TAGS, key = "#root.method.name")
5959
public List<Tag> getAllTags(){
60-
List<Tag> tags = tagRepository.findAll();
61-
62-
return tags;
60+
return tagRepository.findAll();
6361
}
6462

6563
}

0 commit comments

Comments
 (0)
X Tutup