Skip to content

Commit e717501

Browse files
committed
fix: 관련 아티클 tagtype null filter 수정
1 parent 1733388 commit e717501

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/main/java/com/davcatch/devcatch/repository/article/ArticleRepositoryCustomImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,14 @@ public Optional<ArticleResponse> findArticleDetail(Long articleId) {
159159

160160
@Override
161161
public List<ArticleResponse> findRelatedArticles(Long articleId, List<TagType> tagTypes) {
162-
if (tagTypes == null || tagTypes.isEmpty())
163-
return Collections.emptyList();
164-
165162
Map<Long, ArticleResponse> transform = queryFactory
166163
.from(article)
167164
.join(article.source, source)
168165
.join(article.articleTags, articleTag)
169166
.join(articleTag.tag, tag)
170167
.where(
171168
article.id.ne(articleId),
172-
tag.tagType.in(tagTypes)
169+
tag.tagType.in(tagTypes).isNull()
173170
)
174171
.orderBy(article.publishedAt.desc())
175172
.limit(RELATED_ARTICLE_SIZE)

src/main/java/com/davcatch/devcatch/web/service/article/ArticleCommendService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.davcatch.devcatch.web.service.article;
22

3+
import java.util.Collections;
34
import java.util.List;
5+
import java.util.Objects;
46

57
import org.springframework.data.domain.Page;
68
import org.springframework.data.domain.Pageable;
@@ -65,7 +67,16 @@ public ArticleResponse getArticleDetail(Long articleId) throws CustomException {
6567
* @return 아티클 리스트
6668
*/
6769
public List<ArticleResponse> getRelatedArticles(Long articleId, List<TagType> tagTypes) {
68-
return articleRepository.findRelatedArticles(articleId, tagTypes);
70+
List<TagType> filteredNullTagTypes = tagTypes == null ?
71+
Collections.emptyList() :
72+
tagTypes.stream()
73+
.filter(Objects::nonNull)
74+
.toList();
75+
76+
if (filteredNullTagTypes.isEmpty())
77+
return Collections.emptyList();
78+
79+
return articleRepository.findRelatedArticles(articleId, filteredNullTagTypes);
6980
}
7081

7182
}

0 commit comments

Comments
 (0)