-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feature/#243] 디스코드 알림 연동 #247
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
822547f
[#243] feat: 디스코드 회원가입 알림
mmihye fce6727
[#243] feat: 디스코드 회원가입 + 에러 알림
mmihye 83e5387
[#243] feat: 로컬에서는 에러메시지 전송되지 않도록 수정
mmihye f947bdf
[#243] fix: 오타수정
mmihye 81f6717
[#243] fix: 회원가입시 디스코드 알림 에러 예외처리
mmihye a0f568f
[#243] fix: 오타수정
mmihye ad8cbd5
[#243] feat: TransactionalEventListener 추가
mmihye fcc6b29
Merge branch 'develop' into feature/#243
sss4920 d8bb06f
[#243] feat: TransactionalEventListener 적용 및 DiscordClient 통합
mmihye 6cc7f8b
Merge remote-tracking branch 'origin/feature/#243' into feature/#243
mmihye 898fa9d
[#243] fix: 필요없는 import 삭제
mmihye 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 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 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 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
10 changes: 10 additions & 0 deletions
10
linkmind/src/main/java/com/app/toaster/controller/HealthCheckController.java
This file contains 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 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
12 changes: 12 additions & 0 deletions
12
linkmind/src/main/java/com/app/toaster/external/client/discord/DiscordErrorClient.java
This file contains 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,12 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient(name = "${discord.sign-name}", url = "${discord.webhook-url-error}") | ||
public interface DiscordErrorClient { | ||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
void sendMessage(@RequestBody DiscordMessage discordMessage); | ||
} |
29 changes: 29 additions & 0 deletions
29
linkmind/src/main/java/com/app/toaster/external/client/discord/DiscordMessage.java
This file contains 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,29 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class DiscordMessage { | ||
|
||
private String content; | ||
private List<Embed> embeds; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public static class Embed { | ||
|
||
private String title; | ||
private String description; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
linkmind/src/main/java/com/app/toaster/external/client/discord/DiscordMessageProvider.java
This file contains 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,107 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.ApplicationContextException; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.ServletWebRequest; | ||
import org.springframework.web.context.request.WebRequest; | ||
|
||
import com.app.toaster.exception.Error; | ||
import com.app.toaster.exception.model.CustomException; | ||
import com.app.toaster.infrastructure.UserRepository; | ||
|
||
import feign.FeignException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class DiscordMessageProvider { | ||
private final DiscordSingUpClient discordSingUpClient; | ||
private final UserRepository userRepository; | ||
private final Environment environment; | ||
|
||
public void sendNotification(NotificationType type, Exception e, String request) { | ||
if (!Arrays.asList(environment.getActiveProfiles()).contains("local")) { | ||
try { | ||
switch (type){ | ||
case ERROR -> discordSingUpClient.sendMessage(createErrorMessage(e,request)); | ||
case SINGUP -> discordSingUpClient.sendMessage(createSingUpMessage()); | ||
} | ||
} catch (FeignException error) { | ||
throw new CustomException(Error.INVALID_DISCORD_MESSAGE, | ||
Error.INVALID_APPLE_IDENTITY_TOKEN.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
private DiscordMessage createSingUpMessage() { | ||
return DiscordMessage.builder() | ||
.content("# 😍 회원가입 이벤트가 발생했습니다.") | ||
.embeds( | ||
List.of( | ||
DiscordMessage.Embed.builder() | ||
.title("ℹ️ 회원가입 정보") | ||
.description( | ||
"### 🕖 발생 시간\n" | ||
+ LocalDateTime.now() | ||
+ "\n" | ||
+ "### 📜 유저 가입 정보\n" | ||
+ "토스터의 " + userRepository.count() + "번째 유저가 생성되었습니다!! ❤️" | ||
+ "\n") | ||
.build() | ||
) | ||
) | ||
.build(); | ||
} | ||
|
||
|
||
private DiscordMessage createErrorMessage(Exception e, String requestUrl) { | ||
return DiscordMessage.builder() | ||
.content("# 🚨 삐용삐용 에러났어요 에러났어요") | ||
.embeds( | ||
List.of( | ||
DiscordMessage.Embed.builder() | ||
.title("ℹ️ 에러 정보") | ||
.description( | ||
"### 🕖 발생 시간\n" | ||
+ LocalDateTime.now() | ||
+ "\n" | ||
+ "### 🔗 요청 URL\n" | ||
+ requestUrl | ||
+ "\n" | ||
+ "### 📄 Stack Trace\n" | ||
+ "```\n" | ||
+ getStackTrace(e).substring(0, 1000) | ||
+ "\n```") | ||
.build() | ||
) | ||
) | ||
.build(); | ||
} | ||
|
||
private String createRequestFullPath(WebRequest webRequest) { | ||
HttpServletRequest request = ((ServletWebRequest) webRequest).getRequest(); | ||
String fullPath = request.getMethod() + " " + request.getRequestURL(); | ||
|
||
String queryString = request.getQueryString(); | ||
if (queryString != null) { | ||
fullPath += "?" + queryString; | ||
} | ||
|
||
return fullPath; | ||
} | ||
|
||
private String getStackTrace(Exception e) { | ||
StringWriter stringWriter = new StringWriter(); | ||
e.printStackTrace(new PrintWriter(stringWriter)); | ||
return stringWriter.toString(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
linkmind/src/main/java/com/app/toaster/external/client/discord/DiscordSingUpClient.java
This file contains 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,12 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient(name = "${discord.error-name}", url = "${discord.webhook-url-sign}") | ||
public interface DiscordSingUpClient { | ||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
void sendMessage(@RequestBody DiscordMessage discordMessage); | ||
} |
6 changes: 6 additions & 0 deletions
6
linkmind/src/main/java/com/app/toaster/external/client/discord/NotificationType.java
This file contains 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,6 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
public enum NotificationType { | ||
ERROR, | ||
SINGUP | ||
} |
Oops, something went wrong.
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.
옹 좋은데 SignUpMessage()로 오타정도만 나중에 수정해주면 좋을거같네용☺️