Skip to content

Commit

Permalink
Merge pull request #51 from NewsFit-jolp/Fix/#32-preferred-press
Browse files Browse the repository at this point in the history
Fix/#32 preferred press
  • Loading branch information
k000927 authored Oct 27, 2024
2 parents 79d58bf + 5f3c394 commit 0bda3db
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 12 deletions.
106 changes: 105 additions & 1 deletion src/main/java/com/example/newsfit/domain/article/entity/Press.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,109 @@
package com.example.newsfit.domain.article.entity;

public enum Press {
CHOSUN, JOONGANG, DONGA
// 종합
경향신문,
국민일보,
동아일보,
문화일보,
서울신문,
세계일보,
조선일보,
중앙일보,
한겨레,
한국일보,

// 방송/통신
뉴스1,
뉴시스,
연합뉴스,
연합뉴스TV,
채널A,
한국경제TV,
JTBC,
KBS,
MBC,
MBN,
SBS,
SBSBiz,
TV조선,
YTN,

// 경제
매일경제,
머니투데이,
비즈워치,
서울경제,
아시아경제,
이데일리,
조선비즈,
조세일보,
파이낸셜뉴스,
한국경제,
헤럴드경제,

// 인터넷
노컷뉴스,
더팩트,
데일리안,
머니S,
미디어오늘,
아이뉴스24,
오마이뉴스,
프레시안,

// IT
디지털데일리,
디지털타임스,
블로터,
전자신문,
지디넷코리아,

// 매거진
더스쿠프,
레이디경향,
매경이코노미,
시사IN,
시사저널,
신동아,
월간산,
이코노미스트,
주간경향,
주간동아,
주간조선,
중앙SUNDAY,
한겨레21,
한경비즈니스,

// 전문지
기자협회보,
농민신문,
뉴스타파,
동아사이언스,
여성신문,
일다,
코리아중앙데일리,
코리아헤럴드,
코메디닷컴,
헬스조선,

// 지역
강원도민일보,
광주일보,
경기일보,
국제신문,
대구MBC,
대전일보,
매일신문,
부산일보,
전주MBC,
CJB청주방송,
JIBS,
kbc광주방송,

// 포토
신화사,
연합뉴스포토,
AP,
EPA
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.newsfit.domain.article.entity.Article;
import com.example.newsfit.domain.article.entity.Category;
import com.example.newsfit.domain.article.entity.Press;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -14,13 +15,13 @@
public interface ArticleRepository extends JpaRepository<Article, Long> {


List<Article> findAllByOrderByArticleIdDesc(Pageable pageable);
List<Article> findByPressInOrderByArticleIdDesc(List<Press> pressList, Pageable pageable);

List<Article> findByCategoryOrderByArticleIdDesc(Category category, Pageable pageable);
List<Article> findByCategoryAndPressInOrderByArticleIdDesc(Category category, List<Press> pressList, Pageable pageable);

List<Article> findByArticleIdLessThanOrderByArticleIdDesc(Long ArticleId, Pageable pageable);
List<Article> findByArticleIdLessThanAndPressInOrderByArticleIdDesc(Long ArticleId, List<Press> pressList, Pageable pageable);

List<Article> findByArticleIdLessThanAndCategoryOrderByArticleIdDesc(Long ArticleId, Category category, Pageable pageable);
List<Article> findByArticleIdLessThanAndCategoryAndPressInOrderByArticleIdDesc(Long ArticleId, Category category, List<Press> pressList, Pageable pageable);

@Query("SELECT DISTINCT a FROM Article a " +
"WHERE (a.title LIKE %:keyword% OR CAST(a.category AS string) LIKE %:keyword%) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public GetArticles postArticle(String requestBody) throws ParseException {
}

public List<GetArticles> getArticles(String category, Long articleCursor, int size) {
Member member = memberRepository.findByMemberId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));

Category categoryEnum = null;

if (!"allCategory".equalsIgnoreCase(category)) {
Expand All @@ -87,7 +90,8 @@ public List<GetArticles> getArticles(String category, Long articleCursor, int si
}
}

List<Article> articles = getArticlesByCursor(categoryEnum, articleCursor, size);
List<Press> preferredPress = member.getPreferredPress();
List<Article> articles = getArticlesByCursor(categoryEnum, articleCursor, size, preferredPress);
List<GetArticles> returnArticles = new ArrayList<>();
for (Article article : articles) {
GetArticles getArticle = GetArticles.of(article);
Expand Down Expand Up @@ -229,16 +233,16 @@ public Boolean deleteCommentLikes(String articleId, String commentId) {
return true;
}

private List<Article> getArticlesByCursor(Category category, Long articleId, int size) {
private List<Article> getArticlesByCursor(Category category, Long articleId, int size, List<Press> preferredPress) {
Pageable pageable = PageRequest.of(0, size);
if (category == null) {
return articleId == null ?
articleRepository.findAllByOrderByArticleIdDesc(pageable) :
articleRepository.findByArticleIdLessThanOrderByArticleIdDesc(articleId, pageable);
articleRepository.findByPressInOrderByArticleIdDesc(preferredPress, pageable) :
articleRepository.findByArticleIdLessThanAndPressInOrderByArticleIdDesc(articleId, preferredPress, pageable);
} else {
return articleId == null ?
articleRepository.findByCategoryOrderByArticleIdDesc(category, pageable) :
articleRepository.findByArticleIdLessThanAndCategoryOrderByArticleIdDesc(articleId, category, pageable);
articleRepository.findByCategoryAndPressInOrderByArticleIdDesc(category, preferredPress, pageable) :
articleRepository.findByArticleIdLessThanAndCategoryAndPressInOrderByArticleIdDesc(articleId, category, preferredPress, pageable);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public record GetMemberInfo(
) {
public static GetMemberInfo of(Member member) {
return new GetMemberInfo(
member.getEmail(),
member.getNickname(),
member.getEmail(),
member.getProfileImage(),
member.getPhone(),
member.getBirth(),
Expand Down

0 comments on commit 0bda3db

Please sign in to comment.