Skip to content

Commit

Permalink
✨ [feat] 태그로 내가 스크랩한 게시글 미리보기 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
y2hscmtk committed Aug 4, 2024
1 parent a120e90 commit e1ef96c
Show file tree
Hide file tree
Showing 24 changed files with 24 additions and 14 deletions.
Binary file modified .gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
// 오늘 작성된 게시글 찾기
@Query("SELECT a FROM Article a WHERE a.createdAt >= :startTime AND a.createdAt <= :endTime")
List<Article> findAllByCreatedAtBetween(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

@Query("SELECT a FROM Article a JOIN a.tags at JOIN at.tag t JOIN a.scrapList s WHERE s.member.id = :memberId AND t.tagName = :tagName ORDER BY a.createdAt DESC")
Page<Article> findScrappedArticlesByTag(@Param("memberId") Long memberId, @Param("tagName") String tagName, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public interface ArticleTagRepository extends JpaRepository<ArticleTag,Long> {
// 태그 이름으로 묶어서 내림차순 추출
@Query("SELECT at.tag.tagName, COUNT(at) FROM ArticleTag at WHERE at.article IN :articles GROUP BY at.tag.tagName ORDER BY COUNT(at) DESC")
List<Object[]> findTopTagsByArticles(@Param("articles") List<Article> articles);

// 회원이 스크랩한 게시글 중 특정 태그에 해당하는 게시글 페이징 조회
@Query("SELECT at FROM ArticleTag at JOIN at.article a JOIN a.scrapList sc WHERE sc.member = :member and at.tag = :tag ORDER BY a.createdAt DESC")
Page<ArticleTag> findScrapArticleTagPageByTag(Member member, Tag tag, Pageable pageable);
//
// // 회원이 스크랩한 게시글 중 특정 태그에 해당하는 게시글 페이징 조회
// @Query("SELECT at FROM ArticleTag at JOIN at.article a JOIN a.scrapList sc WHERE sc.member = :member and at.tag = :tag ORDER BY a.createdAt DESC")
// Page<ArticleTag> findScrapArticleTagPageByTag(Member member, Tag tag, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public ResponseEntity<?> getAllMyScrapArticles(
return scrapService.getAllMyScrapArticles(userDetails.getEmail(), pageable);
}

/**
* 태그로 내가 스크랩한 게시글 조회(미리보기)
*/
@GetMapping("/mine/tag")
public ResponseEntity<?> getAllMyScrapArticlesByTag(
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestParam String tagName,
Pageable pageable) {
return scrapService.getAllMyScrapArticlesByTag(userDetails.getEmail(), tagName, pageable);
}

/**
* 스크랩 취소
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class ScrapService {
private final ScrapRepository scrapRepository;
private final MemberRepository memberRepository;
private final ArticleRepository articleRepository;
private final TagRepository tagRepository;
private final ArticleTagRepository articleTagRepository;

public ResponseEntity<?> scrapArticle(String email, Long articleId) {
// 1. 회원 조회
Expand Down Expand Up @@ -105,15 +103,13 @@ public ResponseEntity<?> getAllMyScrapArticlesByTag(String email, String tagName
// 1. 사용자 정보 얻어오기
Member member = memberRepository.findMemberByEmail(email)
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
// 2. 태그 정보 얻어오기
Tag tag = tagRepository.findByTagName(tagName)
.orElseThrow(() -> new GeneralException(ErrorStatus.TAG_NOT_FOUND));
// 3. 해당 회원이 스크랩한 태그 정보 조회
Page<ArticleTag> scrapArticleTagPageByTag = articleTagRepository.findScrapArticleTagPageByTag(member, tag, pageable);
int totalPages = scrapArticleTagPageByTag.getTotalPages();

// 2. 해당 회원이 스크랩한 태그 정보 조회
Page<Article> scrappedArticlesByTag = articleRepository.findScrappedArticlesByTag(member.getId(), tagName, pageable);
int totalPages = scrappedArticlesByTag.getTotalPages();

List<ArticlePreviewDto.AllArticlePreview> articlePreviewList = new ArrayList<>();
for (ArticleTag articleTag : scrapArticleTagPageByTag.getContent()) {
Article article = articleTag.getArticle();
for (Article article : scrappedArticlesByTag.getContent()) {
// 관련 태그들 얻어오기
List<TagResponseDto> tagResponseDtoList = article.getTags().stream()
.map(at -> TagResponseDto.builder()
Expand Down

0 comments on commit e1ef96c

Please sign in to comment.