-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
121 additions
and
35 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
33 changes: 22 additions & 11 deletions
33
src/main/java/page/clab/api/global/common/slack/application/SlackService.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 |
---|---|---|
@@ -1,48 +1,59 @@ | ||
package page.clab.api.global.common.slack.application; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
import page.clab.api.domain.community.board.domain.SlackBoardInfo; | ||
import page.clab.api.domain.hiring.application.application.dto.request.ApplicationRequestDto; | ||
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberLoginInfoDto; | ||
import page.clab.api.global.common.slack.domain.ExecutivesAlertType; | ||
import page.clab.api.global.common.slack.domain.GeneralAlertType; | ||
import page.clab.api.global.common.slack.domain.SecurityAlertType; | ||
import page.clab.api.global.common.slack.domain.SlackBoardInfo; | ||
import page.clab.api.global.common.slack.domain.SlackMembershipFeeInfo; | ||
import page.clab.api.global.common.slack.event.NotificationEvent; | ||
import page.clab.api.global.config.SlackConfig; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SlackService { | ||
|
||
private final ApplicationEventPublisher eventPublisher; | ||
private final String coreTeamWebhookUrl; | ||
private final String executivesWebhookUrl; | ||
|
||
public SlackService(ApplicationEventPublisher eventPublisher, SlackConfig slackConfig) { | ||
this.eventPublisher = eventPublisher; | ||
this.coreTeamWebhookUrl = slackConfig.getCoreTeamWebhookUrl(); | ||
this.executivesWebhookUrl = slackConfig.getExecutivesWebhookUrl(); | ||
} | ||
|
||
public void sendServerErrorNotification(HttpServletRequest request, Exception e) { | ||
eventPublisher.publishEvent(new NotificationEvent(this, GeneralAlertType.SERVER_ERROR, request, e)); | ||
eventPublisher.publishEvent(new NotificationEvent(this, coreTeamWebhookUrl, GeneralAlertType.SERVER_ERROR, request, e)); | ||
} | ||
|
||
public void sendSecurityAlertNotification(HttpServletRequest request, SecurityAlertType alertType, String additionalMessage) { | ||
eventPublisher.publishEvent(new NotificationEvent(this, alertType, request, additionalMessage)); | ||
eventPublisher.publishEvent(new NotificationEvent(this, coreTeamWebhookUrl, alertType, request, additionalMessage)); | ||
} | ||
|
||
public void sendAdminLoginNotification(HttpServletRequest request, MemberLoginInfoDto loginMember) { | ||
eventPublisher.publishEvent(new NotificationEvent(this, GeneralAlertType.ADMIN_LOGIN, request, loginMember)); | ||
eventPublisher.publishEvent(new NotificationEvent(this, coreTeamWebhookUrl, GeneralAlertType.ADMIN_LOGIN, request, loginMember)); | ||
} | ||
|
||
public void sendNewApplicationNotification(ApplicationRequestDto applicationRequestDto) { | ||
eventPublisher.publishEvent(new NotificationEvent(this, GeneralAlertType.APPLICATION_CREATED, null, applicationRequestDto)); | ||
eventPublisher.publishEvent(new NotificationEvent(this, executivesWebhookUrl, ExecutivesAlertType.NEW_APPLICATION, null, applicationRequestDto)); | ||
} | ||
|
||
public void sendNewBoardNotification(SlackBoardInfo board) { | ||
eventPublisher.publishEvent(new NotificationEvent(this, GeneralAlertType.BOARD_CREATED, null, board)); | ||
eventPublisher.publishEvent(new NotificationEvent(this, executivesWebhookUrl, ExecutivesAlertType.NEW_BOARD, null, board)); | ||
} | ||
|
||
public void sendNewMembershipFeeNotification(SlackMembershipFeeInfo membershipFee) { | ||
eventPublisher.publishEvent(new NotificationEvent(this, executivesWebhookUrl, ExecutivesAlertType.NEW_MEMBERSHIP_FEE, null, membershipFee)); | ||
} | ||
|
||
@EventListener(ContextRefreshedEvent.class) | ||
public void sendServerStartNotification() { | ||
eventPublisher.publishEvent(new NotificationEvent(this, GeneralAlertType.SERVER_START, null, null)); | ||
eventPublisher.publishEvent(new NotificationEvent(this, coreTeamWebhookUrl, GeneralAlertType.SERVER_START, null, null)); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/page/clab/api/global/common/slack/domain/ExecutivesAlertType.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,16 @@ | ||
package page.clab.api.global.common.slack.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ExecutivesAlertType implements AlertType { | ||
|
||
NEW_APPLICATION("새 지원서", "New application has been submitted."), | ||
NEW_BOARD("새 게시글", "New board has been posted."), | ||
NEW_MEMBERSHIP_FEE("새 회비 신청", "New membership fee has been submitted."); | ||
|
||
private final String title; | ||
private final String defaultMessage; | ||
} |
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
5 changes: 2 additions & 3 deletions
5
...ommunity/board/domain/SlackBoardInfo.java → ...l/common/slack/domain/SlackBoardInfo.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
27 changes: 27 additions & 0 deletions
27
src/main/java/page/clab/api/global/common/slack/domain/SlackMembershipFeeInfo.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,27 @@ | ||
package page.clab.api.global.common.slack.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberBasicInfoDto; | ||
import page.clab.api.domain.members.membershipFee.domain.MembershipFee; | ||
|
||
@Getter | ||
@Builder | ||
public class SlackMembershipFeeInfo { | ||
|
||
private String memberId; | ||
private String memberName; | ||
private String category; | ||
private Long amount; | ||
private String content; | ||
|
||
public static SlackMembershipFeeInfo create(MembershipFee membershipFee, MemberBasicInfoDto memberInfo) { | ||
return SlackMembershipFeeInfo.builder() | ||
.memberId(memberInfo.getMemberId()) | ||
.memberName(memberInfo.getMemberName()) | ||
.category(membershipFee.getCategory()) | ||
.content(membershipFee.getContent()) | ||
.amount(membershipFee.getAmount()) | ||
.build(); | ||
} | ||
} |
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