From d29e36e807ad2b02a0b33653eacce2eaddd69ab1 Mon Sep 17 00:00:00 2001 From: gracefulBrown Date: Sun, 2 Jun 2024 12:18:46 +0900 Subject: [PATCH] fix(article): adjust the number of Slack messages --- .../article/application/ArticleService.java | 16 +++++++++++----- .../wooteco/prolog/article/domain/ImageUrl.java | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java b/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java index 4700aec54..cfb2d9068 100644 --- a/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java +++ b/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java @@ -1,6 +1,8 @@ package wooteco.prolog.article.application; import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +32,8 @@ @Transactional(readOnly = true) public class ArticleService { + private static final Logger logger = LoggerFactory.getLogger(ArticleService.class); + private final ArticleRepository articleRepository; private final MemberService memberService; private final SlackService slackService; @@ -139,12 +143,17 @@ private List fetchArticleWithRssFeedOf(Member member) { } List
persistNewArticles = articleRepository.saveAll(newArticles); - persistNewArticles.forEach(slackService::sendSlackMessage); + + // 가장 최신의 글만 슬랙 메시지로 알림 + persistNewArticles.stream() + .max(Comparator.comparing(Article::getPublishedAt)) + .ifPresent(slackService::sendSlackMessage); return persistNewArticles.stream() .map(article -> ArticleResponse.of(article, member.getId())) .collect(toList()); } catch (Exception e) { + logger.error("Failed to fetch RSS feed for member: " + member.getId(), e); throw new RssFeedException("Failed to fetch RSS feed for member: " + member.getId(), e); } } @@ -158,14 +167,11 @@ private List fetchArticleWhenMemberUpdated(Member member) { List
persistNewArticles = articleRepository.saveAll(newArticles); - persistNewArticles.stream() - .max(Comparator.comparing(Article::getCreatedAt)) - .ifPresent(slackService::sendSlackMessage); - return persistNewArticles.stream() .map(article -> ArticleResponse.of(article, member.getId())) .collect(toList()); } catch (Exception e) { + logger.error("Failed to fetch RSS feed for member: " + member.getId(), e); throw new RssFeedException("Failed to fetch RSS feed for member: " + member.getId(), e); } } diff --git a/backend/src/main/java/wooteco/prolog/article/domain/ImageUrl.java b/backend/src/main/java/wooteco/prolog/article/domain/ImageUrl.java index 7538d0621..bf838d5ad 100644 --- a/backend/src/main/java/wooteco/prolog/article/domain/ImageUrl.java +++ b/backend/src/main/java/wooteco/prolog/article/domain/ImageUrl.java @@ -29,7 +29,7 @@ public ImageUrl(String url) { if (Objects.isNull(url) || url.isEmpty() || url.trim().isEmpty() || url.length() > MAX_LENGTH) { url = "https://avatars.githubusercontent.com/u/45747236?s=200&v=4"; } - this.url = url; + this.url = url.trim(); } public static ImageUrl of(String description, String defaultUrl) {