-
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
Changes from 1 commit
822547f
fce6727
83e5387
f947bdf
81f6717
a0f568f
ad8cbd5
fcc6b29
d8bb06f
6cc7f8b
898fa9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
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.name}", url = "${discord.webhook-url}") | ||
public interface DiscordClient { | ||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
void sendMessage(@RequestBody DiscordMessage discordMessage); | ||
} |
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.app.toaster.external.client.discord; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.springframework.context.ApplicationContextException; | ||
import org.springframework.stereotype.Component; | ||
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 lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class DiscordMessageProvider { | ||
private final DiscordClient discordClient; | ||
private final UserRepository userRepository; | ||
|
||
public void sendSignUpNotification() { | ||
sendMessageToDiscord(createSingUpMessage()); | ||
} | ||
|
||
private void sendMessageToDiscord(DiscordMessage discordMessage) { | ||
try { | ||
discordClient.sendMessage(discordMessage); | ||
} catch (FeignException e) { | ||
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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.app.toaster.service.auth; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.context.request.WebRequest; | ||
|
||
import com.app.toaster.common.dto.ApiResponse; | ||
import com.app.toaster.config.jwt.JwtService; | ||
|
@@ -21,6 +23,8 @@ | |
import com.app.toaster.exception.model.CustomException; | ||
import com.app.toaster.exception.model.NotFoundException; | ||
import com.app.toaster.exception.model.UnprocessableEntityException; | ||
import com.app.toaster.external.client.discord.DiscordMessage; | ||
import com.app.toaster.external.client.discord.DiscordMessageProvider; | ||
import com.app.toaster.external.client.slack.SlackApi; | ||
import com.app.toaster.infrastructure.CategoryRepository; | ||
import com.app.toaster.infrastructure.TimerRepository; | ||
|
@@ -48,6 +52,7 @@ public class AuthService { | |
private final PopupManagerRepository popupManagerRepository; | ||
|
||
private final SlackApi slackApi; | ||
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. 이렇게 되면 SlackApi도 같이 이 pr에서 제거해주실 수 있을까용?🐱 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. 혹시 SlackApi 관련 클래스 모두 삭제하는것을 말하는걸까요...? 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. 아 흠 클래스까지 다 지우기에 좀.. 그렇네용 아까운뎅 ㅜ 일단 보류하는거 어떻게 생각하시나용;?ㅋㅋ 줏대 없어서 죄송합니당😢 |
||
private final DiscordMessageProvider discordMessageProvider; | ||
|
||
|
||
private final Long TOKEN_EXPIRATION_TIME_ACCESS = 7*24*60 * 60 * 1000L; //7일 | ||
|
@@ -76,7 +81,8 @@ public SignInResponseDto signIn(String socialAccessToken, SignInRequestDto reque | |
.socialType(socialType).build(); | ||
newUser.updateFcmIsAllowed(true); //신규 유저면 true박고 | ||
userRepository.save(newUser); | ||
slackApi.sendSuccess(Success.LOGIN_SUCCESS); | ||
// slackApi.sendSuccess(Success.LOGIN_SUCCESS); | ||
discordMessageProvider.sendSignUpNotification(); | ||
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. 흠 여기서 궁금한게 최근 트랜잭션 전파단계에 대해서 공부하긴했었는데 실제로 사례로보니 더 헷갈리는거같네용 ㅠ 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. 엇 그러고 보니 알림에서 에러가 나면 모든로직이 롤백될거같네요... 81f6717 다음과 같이 Try-Catch 문을 사용하여 에러 발생하면 로그찍고넘어가는 걸로 고쳐봤는데 이렇게하면 괜찮을까요? 혹시 좋은방법이나 아이디어있으시면 말씀해주세용 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. 흠.. 일단 로그찍는것도 임시방편으로 나쁘지않은 것 같습니다!! 약간 아이디어는 트랜잭션을 분리시키는 방법이 있을 것 같긴합니다..! 일단 우리단과 비슷한 경우인 듯합니당. 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. 옹 새로운 방식이네요 한번 공부해보고 적용해보겠습니다! |
||
} | ||
|
||
User user = userRepository.findBySocialIdAndSocialType(socialId, socialType) | ||
|
@@ -167,4 +173,5 @@ public TokenHealthDto checkHealthOfToken(String refreshToken){ | |
return TokenHealthDto.of(jwtService.verifyToken(refreshToken)); | ||
} | ||
|
||
|
||
} |
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()로 오타정도만 나중에 수정해주면 좋을거같네용☺️