feat : Get List Article Implement.?

This commit is contained in:
minseokkang
2022-11-09 11:30:34 +09:00
parent 02619a57dc
commit 27f13bbff0
2 changed files with 15 additions and 3 deletions

View File

@@ -10,8 +10,13 @@ import java.util.List;
public interface ArticleRepository extends JpaRepository<Article,Long> {
@EntityGraph(attributePaths = "tags")
@EntityGraph(attributePaths = "tagList")
@Query("SELECT a FROM Article a JOIN Tag t ON a.id = t.article.id")
List<Article> findByTag(String tag, Pageable pageable);
@Query("SELECT a FROM Article a WHERE a.author.username = :author")
List<Article> findByAuthorName(String author, Pageable pageable);
@Query("SELECT a FROM Article a LEFT JOIN Favorite f ON f.article.id = a.id WHERE f.user.username =:username")
List<Article> findByFavoritedUser(String username, Pageable pageable);
}

View File

@@ -55,7 +55,14 @@ public class ArticleServiceImpl implements ArticleService {
if (articleParam.getTag() != null) {
articles = articleRepository.findByTag(articleParam.getTag(), pageable);
}
System.out.println(articles.size());
if(articleParam.getAuthor() != null){
articles = articleRepository.findByAuthorName(articleParam.getAuthor(), pageable);
}
if(articleParam.getFavorited() != null){
articles = articleRepository.findByFavoritedUser(articleParam.getFavorited(), pageable);
}
return articles.stream().map(article -> {
return convertDtoWithUser(article, userAuth);