bugfix for query by author name and favorited username
This commit is contained in:
parent
288f2d4c14
commit
4550e5a3c5
@ -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'
|
||||
|
@ -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
|
||||
<where>
|
||||
<if test="tag != null">
|
||||
T.name = #{tag}
|
||||
</if>
|
||||
<if test="author != null">
|
||||
AND A.user_id = #{author}
|
||||
AND AU.username = #{author}
|
||||
</if>
|
||||
<if test="favoritedBy != null">
|
||||
AND AF.user_id = #{favoritedBy}
|
||||
AND AFU.username = #{favoritedBy}
|
||||
</if>
|
||||
</where>
|
||||
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
|
||||
<where>
|
||||
<if test="tag != null">
|
||||
T.name = #{tag}
|
||||
</if>
|
||||
<if test="author != null">
|
||||
AND A.user_id = #{author}
|
||||
AND AU.username = #{author}
|
||||
</if>
|
||||
<if test="favoritedBy != null">
|
||||
AND AF.user_id = #{favoritedBy}
|
||||
AND AFU.username = #{favoritedBy}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user