-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Send message when a user registers or creates a group #386
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
Changes from all commits
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,48 @@ | ||
| package com.gamzabat.algohub.common.logging; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.util.StringUtils; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class DiscordWebhookService { | ||
| @Value("${noti_url:}") | ||
| private String webhookUrl; | ||
|
|
||
| private final RestTemplate restTemplate; | ||
|
|
||
| public void sendRegisterMessage(String username, String type, Long sid) { | ||
| String content = username + " λμ΄ " + type + " λ°©μμΌλ‘ " + sid + "λ²μ§Έλ‘ νμκ°μ νμ ¨μ΅λλ€!! π"; | ||
| this.send(content); | ||
| } | ||
|
|
||
| public void sendCreateGroupMessage(String username, String groupName) { | ||
| String content = username + " λμ΄ " + groupName + " κ·Έλ£Ήμ μμ±νμ ¨μ΅λλ€ π"; | ||
| this.send(content); | ||
| } | ||
|
|
||
| private void send(String message) { | ||
| try { | ||
| if (!StringUtils.hasText(webhookUrl)) { | ||
| log.debug("No webhook url provided"); | ||
| return; | ||
|
Comment on lines
+35
to
+37
Contributor
Author
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. webhook-prod.ymlμλ§ λ Έν° μ£Όμ λ£μμ΅λλ€. λλ¨Έμ§ μ€ν
μ΄μ§λ©΄ 무μνλ €κ³ νκ±°κ³ , λ€λ₯Έ ꡬν νλν°μ€λ |
||
| } | ||
| Map<String, String> payload = new HashMap<>(); | ||
| payload.put("content", message); | ||
| restTemplate.postForObject(webhookUrl, payload, String.class); | ||
| log.info("Webhook sent: {}", message); | ||
| } catch (Exception e) { | ||
| log.error("Error sending webhook message", e); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import com.gamzabat.algohub.common.jwt.TokenProvider; | ||
| import com.gamzabat.algohub.common.jwt.dto.JwtDTO; | ||
| import com.gamzabat.algohub.common.jwt.dto.ReissueTokenRequest; | ||
| import com.gamzabat.algohub.common.logging.DiscordWebhookService; | ||
| import com.gamzabat.algohub.common.redis.RedisService; | ||
| import com.gamzabat.algohub.enums.EmailType; | ||
| import com.gamzabat.algohub.enums.ImageType; | ||
|
|
@@ -74,6 +75,7 @@ public class UserService { | |
| private final RestTemplate restTemplate; | ||
| private final ResetPasswordRepository resetPasswordRepository; | ||
| private final EmailService emailService; | ||
| private final DiscordWebhookService webhookService; | ||
|
|
||
| @Transactional | ||
| public void register(RegisterRequest request, MultipartFile profileImage, String token) { | ||
|
|
@@ -94,6 +96,8 @@ public void register(RegisterRequest request, MultipartFile profileImage, String | |
|
|
||
| saveProfileImage(profileImage, user); | ||
| log.info("success to register user_id={}", user.getId()); | ||
|
|
||
| webhookService.sendRegisterMessage(user.getNickname(), "SignUp", user.getId()); | ||
|
||
| } | ||
|
|
||
| private void saveProfileImage(MultipartFile profileImage, User user) { | ||
|
|
||
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.
[nitpick] Hardcoding localized strings in code can hinder future localization; consider externalizing message templates or using a message source for maintainability.