Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static in.koreatech.koin.domain.community.article.service.ArticleService.NOTICE_BOARD_ID;

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

Expand All @@ -28,7 +29,7 @@ public interface ArticleRepository extends Repository<Article, Integer> {

Optional<Article> findById(Integer articleId);

List<Article> findAllByIdIn(List<Integer> articleIds);
List<Article> findAllByIdIn(Collection<Integer> articleIds);

Page<Article> findAll(Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package in.koreatech.koin.domain.community.keyword.dto;

import java.util.List;
import java.util.Set;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand All @@ -9,10 +9,10 @@
import jakarta.validation.constraints.NotNull;

@JsonNaming(SnakeCaseStrategy.class)
public record KeywordNotificationRequest (
public record KeywordNotificationRequest(
@Schema(description = "업데이트 된 공지사항 목록", example = "[1, 2, 3]")
@NotNull
List<Integer> updateNotification
Set<Integer> updateNotification
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import in.koreatech.koin.domain.community.article.exception.ArticleNotFoundException;
import in.koreatech.koin.common.event.ArticleKeywordEvent;
import in.koreatech.koin.domain.community.article.dto.ArticleKeywordResult;
import in.koreatech.koin.domain.community.article.model.Article;
import in.koreatech.koin.domain.community.article.repository.ArticleRepository;
Expand All @@ -23,7 +23,6 @@
import in.koreatech.koin.domain.community.keyword.exception.KeywordDuplicationException;
import in.koreatech.koin.domain.community.keyword.exception.KeywordLimitExceededException;
import in.koreatech.koin.domain.community.keyword.model.ArticleKeyword;
import in.koreatech.koin.common.event.ArticleKeywordEvent;
import in.koreatech.koin.domain.community.keyword.model.ArticleKeywordSuggestCache;
import in.koreatech.koin.domain.community.keyword.model.ArticleKeywordUserMap;
import in.koreatech.koin.domain.community.keyword.repository.ArticleKeywordRepository;
Expand Down Expand Up @@ -147,27 +146,11 @@ public ArticleKeywordsSuggestionResponse suggestKeywords() {
}

public void sendKeywordNotification(KeywordNotificationRequest request) {
List<Integer> updateNotificationIds = request.updateNotification().stream()
.distinct()
.toList();

if (updateNotificationIds.isEmpty()) {
if (request.updateNotification().isEmpty()) {
return;
}

List<Article> fetchedArticles = articleRepository.findAllByIdIn(updateNotificationIds);
var articleById = fetchedArticles.stream()
.collect(Collectors.toMap(Article::getId, article -> article));
List<Article> articles = updateNotificationIds.stream()
.map(articleId -> {
Article article = articleById.get(articleId);
if (article == null) {
throw ArticleNotFoundException.withDetail("articleId: " + articleId);
}
return article;
})
.toList();

List<Article> articles = articleRepository.findAllByIdIn(request.updateNotification());
List<ArticleKeywordEvent> keywordEvents = keywordExtractor.matchKeyword(articles, null);
for (ArticleKeywordEvent event : keywordEvents) {
eventPublisher.publishEvent(event);
Expand Down
Loading