From 4550e5a3c582cbb5da4f08cce71a0955f1c4c17d Mon Sep 17 00:00:00 2001 From: aisensiy Date: Sat, 19 Aug 2017 09:55:24 +0800 Subject: [PATCH] bugfix for query by author name and favorited username --- build.gradle | 1 - src/main/resources/mapper/ArticleReadService.xml | 12 ++++++++---- .../application/article/ArticleQueryServiceTest.java | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index f5e17b9..4b8eb6f 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,6 @@ buildscript { apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' -apply plugin: 'findbugs' apply plugin: 'org.springframework.boot' version = '0.0.1-SNAPSHOT' diff --git a/src/main/resources/mapper/ArticleReadService.xml b/src/main/resources/mapper/ArticleReadService.xml index 822c2b1..cde823b 100644 --- a/src/main/resources/mapper/ArticleReadService.xml +++ b/src/main/resources/mapper/ArticleReadService.xml @@ -41,15 +41,17 @@ left join article_tags AT on A.id = AT.article_id left join tags T on T.id = AT.tag_id left join article_favorites AF on AF.article_id = A.id + left join users AU on AU.id = A.user_id + left join users AFU on AFU.id = AF.user_id T.name = #{tag} - AND A.user_id = #{author} + AND AU.username = #{author} - AND AF.user_id = #{favoritedBy} + AND AFU.username = #{favoritedBy} order by A.created_at desc @@ -63,15 +65,17 @@ left join article_tags AT on A.id = AT.article_id left join tags T on T.id = AT.tag_id left join article_favorites AF on AF.article_id = A.id + left join users AU on AU.id = A.user_id + left join users AFU on AFU.id = AF.user_id T.name = #{tag} - AND A.user_id = #{author} + AND AU.username = #{author} - AND AF.user_id = #{favoritedBy} + AND AFU.username = #{favoritedBy} diff --git a/src/test/java/io/spring/application/article/ArticleQueryServiceTest.java b/src/test/java/io/spring/application/article/ArticleQueryServiceTest.java index fccec10..e61acd2 100644 --- a/src/test/java/io/spring/application/article/ArticleQueryServiceTest.java +++ b/src/test/java/io/spring/application/article/ArticleQueryServiceTest.java @@ -107,7 +107,7 @@ public class ArticleQueryServiceTest { Article anotherArticle = new Article("new article", "desc", "body", new String[]{"test"}, anotherUser.getId()); articleRepository.save(anotherArticle); - ArticleDataList recentArticles = queryService.findRecentArticles(null, user.getId(), null, new Page(), user); + ArticleDataList recentArticles = queryService.findRecentArticles(null, user.getUsername(), null, new Page(), user); assertThat(recentArticles.getArticleDatas().size(), is(1)); assertThat(recentArticles.getCount(), is(1)); } @@ -123,7 +123,7 @@ public class ArticleQueryServiceTest { ArticleFavorite articleFavorite = new ArticleFavorite(article.getId(), anotherUser.getId()); articleFavoriteRepository.save(articleFavorite); - ArticleDataList recentArticles = queryService.findRecentArticles(null, null, anotherUser.getId(), new Page(), anotherUser); + ArticleDataList recentArticles = queryService.findRecentArticles(null, null, anotherUser.getUsername(), new Page(), anotherUser); assertThat(recentArticles.getArticleDatas().size(), is(1)); assertThat(recentArticles.getCount(), is(1)); ArticleData articleData = recentArticles.getArticleDatas().get(0);