-
Notifications
You must be signed in to change notification settings - Fork 0
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
12
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
12 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 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
9 changes: 9 additions & 0 deletions
9
src/main/java/gg/agit/konect/domain/user/event/UserRegisterEvent.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 UserRegisterEvent( | ||
| String email | ||
| ) { | ||
| public static UserRegisterEvent from(String email) { | ||
| return new UserRegisterEvent(email); | ||
| } | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
src/main/java/gg/agit/konect/domain/user/event/UserWithdrawEvent.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 UserWithdrawEvent( | ||
| String email | ||
| ) { | ||
| public static UserWithdrawEvent from(String email) { | ||
| return new UserWithdrawEvent(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
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
| 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.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; | ||
|
|
||
| public void sendMessage(String message, String url) { | ||
| try { | ||
| 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 | ||
| ); | ||
| } catch (Exception e) { | ||
| log.error("Slack 메시지 전송 중 오류 발생", 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.UserRegisterEvent; | ||
| import gg.agit.konect.domain.user.event.UserWithdrawEvent; | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순 궁금증인데 서비스 레이어에서 트랜잭션 메소드가 커밋되고 난 뒤 이벤트를 수행하는 구조가 맞나요??? 👀 |
||
| public void handleUserWithdraw(UserWithdrawEvent event) { | ||
| slackNotificationService.notifyUserWithdraw(event.email()); | ||
| } | ||
|
|
||
| @Async | ||
| @TransactionalEventListener(phase = AFTER_COMMIT) | ||
| public void handleUserRegister(UserRegisterEvent 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.
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.
이벤트는 이미 발생한
사건을 표현하므로, 네이밍은 과거형을 사용하는 것이 적절하다고 합니다!링크