-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostEventListener.java
56 lines (48 loc) · 2.22 KB
/
PostEventListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package team05.integrated_feed_backend.module.post.event.listener;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import team05.integrated_feed_backend.common.enums.SocialMediaType;
import team05.integrated_feed_backend.infra.sns.adapter.FacebookAdapter;
import team05.integrated_feed_backend.infra.sns.adapter.InstagramAdapter;
import team05.integrated_feed_backend.infra.sns.adapter.TwitterAdapter;
import team05.integrated_feed_backend.module.post.event.LikeCountIncreasedEvent;
import team05.integrated_feed_backend.module.post.event.ShareCountIncreasedEvent;
@Component
@RequiredArgsConstructor
@Slf4j
public class PostEventListener {
private final FacebookAdapter facebookAdapter;
private final TwitterAdapter twitterAdapter;
private final InstagramAdapter instagramAdapter;
@Async
@EventListener
public void handleLikeCountIncreasedEvent(LikeCountIncreasedEvent event) {
Long postId = event.getPostId();
SocialMediaType type = event.getType();
log.info("Asynchronously handling like count increase event for post ID: {}", postId);
// 외부 API 호출
switch (type) {
case FACEBOOK -> facebookAdapter.increaseLikeCount(postId);
case INSTAGRAM -> instagramAdapter.increaseLikeCount(postId);
case TWITTER -> twitterAdapter.increaseLikeCount(postId);
default -> log.error(postId + " 게시물의 " + type + ": facebook, instagram, twitter 중 하나로 설정되어 있지 않습니다.");
}
}
@Async
@EventListener
public void handleShareCountIncreasedEvent(ShareCountIncreasedEvent event) {
Long postId = event.getPostId();
SocialMediaType type = event.getType();
log.info("Asynchronously handling share count increase event for post ID: {}", postId);
// 외부 API 호출
switch (type) {
case FACEBOOK -> facebookAdapter.increaseShareCount(postId);
case INSTAGRAM -> instagramAdapter.increaseShareCount(postId);
case TWITTER -> twitterAdapter.increaseShareCount(postId);
default -> log.error(postId + " 게시물의 " + type + ": facebook, instagram, twitter 중 하나로 설정되어 있지 않습니다.");
}
}
}