Skip to content

Commit

Permalink
fix(article): adjust the number of Slack messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gracefulBrown committed Jun 2, 2024
1 parent d3c91ff commit d29e36e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -139,12 +143,17 @@ private List<ArticleResponse> fetchArticleWithRssFeedOf(Member member) {
}

List<Article> 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);
}
}
Expand All @@ -158,14 +167,11 @@ private List<ArticleResponse> fetchArticleWhenMemberUpdated(Member member) {

List<Article> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d29e36e

Please sign in to comment.