-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π :: (#230) νΌλ μ κ³ Slack μ°λ
π :: (#230) νΌλ μ κ³ Slack μ°λ
- Loading branch information
1 parent
f2e7b39
commit 8391754
Showing
16 changed files
with
182 additions
and
15 deletions.
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
14 changes: 14 additions & 0 deletions
14
feed-domain/src/main/java/com/xquare/v1servicefeed/user/exception/UserNotFoundException.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,14 @@ | ||
package com.xquare.v1servicefeed.user.exception; | ||
|
||
import com.xquare.v1servicefeed.error.FeedException; | ||
import com.xquare.v1servicefeed.user.error.UserErrorCode; | ||
|
||
public class UserNotFoundException extends FeedException { | ||
|
||
public static final FeedException EXCEPTION = | ||
new UserNotFoundException(); | ||
|
||
private UserNotFoundException() { | ||
super(UserErrorCode.USER_NOT_FOUND); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/SlackReport.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,15 @@ | ||
package com.xquare.v1servicefeed.webhook; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class SlackReport { | ||
|
||
private final String feedContent; | ||
|
||
private final String userName; | ||
|
||
private final String reportContent; | ||
} |
10 changes: 10 additions & 0 deletions
10
feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/spi/SendWebhookSpi.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,10 @@ | ||
package com.xquare.v1servicefeed.webhook.spi; | ||
|
||
import com.xquare.v1servicefeed.annotation.Spi; | ||
import com.xquare.v1servicefeed.webhook.SlackReport; | ||
|
||
@Spi | ||
public interface SendWebhookSpi { | ||
|
||
void sendReportToSlack(SlackReport slackReport); | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...frastructure/src/main/java/com/xquare/v1servicefeed/configuration/config/AsyncConfig.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,9 @@ | ||
package com.xquare.v1servicefeed.configuration.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
|
||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfig { | ||
} |
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
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
46 changes: 46 additions & 0 deletions
46
...frastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventListener.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,46 @@ | ||
package com.xquare.v1servicefeed.webhook; | ||
|
||
import net.gpedro.integrations.slack.SlackApi; | ||
import net.gpedro.integrations.slack.SlackAttachment; | ||
import net.gpedro.integrations.slack.SlackMessage; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SendWebhookEventListener { | ||
|
||
private static final String REPORT_MESSAGE = "νΌλ μ κ³ λ°μ"; | ||
private static final String REPORT_USER_NAME = "μ κ³ μ"; | ||
private static final String REPORT_CONTENT = "μ κ³ λ΄μ©"; | ||
private static final String REPORT_FEED_CONTENT = "μ κ³ λ κ²μκΈ λ΄μ©"; | ||
private static final String MESSAGE_COLOR = "#9650FA"; | ||
private static final String FALLBACK = "μλ‘μ΄ νΌλ μ κ³ κ° λμ°©νμ΅λλ€."; | ||
|
||
@Value("${webhook.url}") | ||
private String webhookUrl; | ||
|
||
@Async | ||
@EventListener | ||
public void sendReportToSlack(SlackReport slackReport) { | ||
SlackAttachment slackAttachment = createSlackAttachment(slackReport); | ||
SlackMessage slackMessage = new SlackMessage("").addAttachments(slackAttachment); | ||
new SlackApi(webhookUrl).call(slackMessage); | ||
} | ||
|
||
private SlackAttachment createSlackAttachment(SlackReport slackReport) { | ||
SlackAttachment slackAttachment = new SlackAttachment(); | ||
slackAttachment.setTitle(REPORT_MESSAGE); | ||
slackAttachment.setText(getErrorReason(slackReport)); | ||
slackAttachment.setColor(MESSAGE_COLOR); | ||
slackAttachment.setFallback(FALLBACK); | ||
return slackAttachment; | ||
} | ||
|
||
private String getErrorReason(SlackReport slackReport) { | ||
return REPORT_USER_NAME + " : " + slackReport.getUserName() | ||
+ "\n" + REPORT_FEED_CONTENT + " : " + slackReport.getFeedContent() | ||
+ "\n" + REPORT_CONTENT + " : " + slackReport.getReportContent(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventPublisher.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,18 @@ | ||
package com.xquare.v1servicefeed.webhook; | ||
|
||
import com.xquare.v1servicefeed.webhook.spi.SendWebhookSpi; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class SendWebhookEventPublisher implements SendWebhookSpi { | ||
|
||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@Override | ||
public void sendReportToSlack(SlackReport slackReport) { | ||
applicationEventPublisher.publishEvent(slackReport); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -46,3 +46,6 @@ springdoc: | |
display-request-duration: true | ||
cache: | ||
disabled: true | ||
|
||
webhook: | ||
url: ${webhook.url} |