-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 이벤트 알림 로직 구현 #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Soundbar91
wants to merge
16
commits into
main
Choose a base branch
from
feat/CAM-144-event-notification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: 이벤트 알림 로직 구현 #102
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
843a41a
build: Slack API Client 의존성 추가
059abb3
feat: UserWithdrawEvent 추가
4ec9194
feat: SlackProperties 추가
a3146bb
feat: SlackClient 추가
3c53e48
feat: SlackMessageTemplate 추가
d2a9ef7
feat: SlackNotificationService 추가
bd0b4e3
feat: UserSlackListener 추가
946afad
feat: 회원 탈퇴 이벤트 발행 로직 추가
32f823c
feat: 회원가입 이벤트 발행 로직 구현
Soundbar91 1842ec4
feat: 회원가입 이벤트 슬랙 알림 로직 구현
Soundbar91 5b55d23
chore: 메소드 네이밍 수정
Soundbar91 aae0594
fix: 충돌 해결
Soundbar91 5f3b6c6
chore: 이벤트 클래스 네이밍 및 이벤트 핸들러 메소드 네이밍 과거형으로 수정
Soundbar91 d68c2aa
feat: 재시도 로직 추가
Soundbar91 6bef2c9
fix: 회원탈퇴 로직 수정 (#103)
Soundbar91 cea3634
chore: 미사용 import 삭제
Soundbar91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/gg/agit/konect/domain/user/event/UserRegisteredEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package gg.agit.konect.domain.user.event; | ||
|
|
||
| public record UserRegisteredEvent( | ||
| String email | ||
| ) { | ||
| public static UserRegisteredEvent from(String email) { | ||
| return new UserRegisteredEvent(email); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/gg/agit/konect/domain/user/event/UserWithdrawnEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package gg.agit.konect.domain.user.event; | ||
|
|
||
| public record UserWithdrawnEvent( | ||
| String email | ||
| ) { | ||
| public static UserWithdrawnEvent from(String email) { | ||
| return new UserWithdrawnEvent(email); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/gg/agit/konect/infrastructure/slack/client/SlackClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package gg.agit.konect.infrastructure.slack.client; | ||
|
|
||
| import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.http.HttpEntity; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.retry.annotation.Recover; | ||
| import org.springframework.retry.annotation.Retryable; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class SlackClient { | ||
|
|
||
| private final RestTemplate restTemplate; | ||
|
|
||
| @Retryable | ||
| public void sendMessage(String message, String url) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setContentType(APPLICATION_JSON); | ||
|
|
||
| Map<String, Object> payload = new HashMap<>(); | ||
| payload.put("text", message); | ||
|
|
||
| HttpEntity<Map<String, Object>> request = new HttpEntity<>(payload, headers); | ||
| restTemplate.postForEntity( | ||
| url, | ||
| request, | ||
| String.class | ||
| ); | ||
| } | ||
|
|
||
| @Recover | ||
| public void sendMessageRecover(Exception e, String message, String url) { | ||
| log.error("Slack 메시지 전송 실패 : message={}, url={}", message, url, e); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/gg/agit/konect/infrastructure/slack/config/SlackProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package gg.agit.konect.infrastructure.slack.config; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| @ConfigurationProperties(prefix = "slack") | ||
| public record SlackProperties( | ||
| Webhooks webhooks | ||
| ) { | ||
| public record Webhooks( | ||
| String error, | ||
| String event | ||
| ) { | ||
|
|
||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/gg/agit/konect/infrastructure/slack/enums/SlackMessageTemplate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package gg.agit.konect.infrastructure.slack.enums; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum SlackMessageTemplate { | ||
|
|
||
| USER_REGISTER( | ||
| """ | ||
| `%s님이 가입하셨습니다.` | ||
| """ | ||
| ), | ||
| USER_WITHDRAWAL( | ||
| """ | ||
| `%s님이 탈퇴하셨습니다.` | ||
| """ | ||
| ), | ||
| ; | ||
|
|
||
| private final String template; | ||
|
|
||
| public String format(Object... args) { | ||
| return String.format(template, args); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/gg/agit/konect/infrastructure/slack/listener/UserSlackListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package gg.agit.konect.infrastructure.slack.listener; | ||
|
|
||
| import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; | ||
|
|
||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.event.TransactionalEventListener; | ||
|
|
||
| import gg.agit.konect.domain.user.event.UserRegisteredEvent; | ||
| import gg.agit.konect.domain.user.event.UserWithdrawnEvent; | ||
| import gg.agit.konect.infrastructure.slack.service.SlackNotificationService; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class UserSlackListener { | ||
|
|
||
| private final SlackNotificationService slackNotificationService; | ||
|
|
||
| @Async | ||
| @TransactionalEventListener(phase = AFTER_COMMIT) | ||
| public void handleUserWithdrawn(UserWithdrawnEvent event) { | ||
| slackNotificationService.notifyUserWithdraw(event.email()); | ||
| } | ||
|
|
||
| @Async | ||
| @TransactionalEventListener(phase = AFTER_COMMIT) | ||
| public void handleUserRegistered(UserRegisteredEvent event) { | ||
| slackNotificationService.notifyUserRegister(event.email()); | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
src/main/java/gg/agit/konect/infrastructure/slack/service/SlackNotificationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package gg.agit.konect.infrastructure.slack.service; | ||
|
|
||
| import static gg.agit.konect.infrastructure.slack.enums.SlackMessageTemplate.USER_REGISTER; | ||
| import static gg.agit.konect.infrastructure.slack.enums.SlackMessageTemplate.USER_WITHDRAWAL; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import gg.agit.konect.infrastructure.slack.client.SlackClient; | ||
| import gg.agit.konect.infrastructure.slack.config.SlackProperties; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class SlackNotificationService { | ||
|
|
||
| private final SlackProperties slackProperties; | ||
| private final SlackClient slackClient; | ||
|
|
||
| public void notifyUserWithdraw(String email) { | ||
| String message = USER_WITHDRAWAL.format(email); | ||
| slackClient.sendMessage(message, slackProperties.webhooks().event()); | ||
| } | ||
|
|
||
| public void notifyUserRegister(String email) { | ||
| String message = USER_REGISTER.format(email); | ||
| slackClient.sendMessage(message, slackProperties.webhooks().event()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단순 궁금증인데 서비스 레이어에서 트랜잭션 메소드가 커밋되고 난 뒤 이벤트를 수행하는 구조가 맞나요??? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
트랜잭션이 정상적으로 커밋이 되면 이벤트를 수행하는 구조 맞습니다