-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: 피드 신고시 discord 알림 기능 구현 * fix: properties사용하는방법으로 수정 * fix: comment기능 merge
- Loading branch information
Showing
6 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...in/java/com/depromeet/stonebed/domain/discord/application/DiscordNotificationService.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,52 @@ | ||
package com.depromeet.stonebed.domain.discord.application; | ||
|
||
import com.depromeet.stonebed.global.error.ErrorCode; | ||
import com.depromeet.stonebed.global.error.exception.CustomException; | ||
import com.depromeet.stonebed.infra.properties.DiscordProperties; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.client.RestClient; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class DiscordNotificationService { | ||
|
||
private final DiscordProperties discordProperties; | ||
private final RestClient restClient; | ||
|
||
public void sendDiscordMessage(String message) { | ||
Map<String, String> payload = new HashMap<>(); | ||
payload.put("content", message); | ||
|
||
try { | ||
String discordWebhookUrl = discordProperties.url(); | ||
log.info("Sending Discord notification to URL: {}", discordWebhookUrl); | ||
|
||
restClient | ||
.post() | ||
.uri(discordWebhookUrl) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.body(payload) | ||
.exchange( | ||
(request, response) -> { | ||
if (!response.getStatusCode().is2xxSuccessful()) { | ||
throw new CustomException( | ||
ErrorCode.DISCORD_NOTIFICATION_FAILED); | ||
} | ||
log.info("Discord 알림 전송 성공: {}", message); | ||
return response.bodyTo(String.class); | ||
}); | ||
|
||
} catch (Exception e) { | ||
log.error("Discord 알림 전송 중 예외 발생: {}", message, e); | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/depromeet/stonebed/infra/properties/DiscordProperties.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.depromeet.stonebed.infra.properties; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "discord") | ||
public record DiscordProperties(String url) {} |
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