diff --git a/src/main/java/page/clab/api/domain/members/membershipFee/application/service/MembershipFeeRegisterService.java b/src/main/java/page/clab/api/domain/members/membershipFee/application/service/MembershipFeeRegisterService.java index 6668720bf..933e4b700 100644 --- a/src/main/java/page/clab/api/domain/members/membershipFee/application/service/MembershipFeeRegisterService.java +++ b/src/main/java/page/clab/api/domain/members/membershipFee/application/service/MembershipFeeRegisterService.java @@ -3,12 +3,15 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberBasicInfoDto; import page.clab.api.domain.members.membershipFee.application.dto.request.MembershipFeeRequestDto; import page.clab.api.domain.members.membershipFee.application.port.in.RegisterMembershipFeeUseCase; import page.clab.api.domain.members.membershipFee.application.port.out.RegisterMembershipFeePort; import page.clab.api.domain.members.membershipFee.domain.MembershipFee; import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase; import page.clab.api.external.memberManagement.notification.application.port.ExternalSendNotificationUseCase; +import page.clab.api.global.common.slack.application.SlackService; +import page.clab.api.global.common.slack.domain.SlackMembershipFeeInfo; @Service @RequiredArgsConstructor @@ -17,13 +20,16 @@ public class MembershipFeeRegisterService implements RegisterMembershipFeeUseCas private final RegisterMembershipFeePort registerMembershipFeePort; private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase; private final ExternalSendNotificationUseCase externalSendNotificationUseCase; + private final SlackService slackService; @Transactional @Override public Long registerMembershipFee(MembershipFeeRequestDto requestDto) { - String currentMemberId = externalRetrieveMemberUseCase.getCurrentMemberId(); - MembershipFee membershipFee = MembershipFeeRequestDto.toEntity(requestDto, currentMemberId); + MemberBasicInfoDto memberInfo = externalRetrieveMemberUseCase.getCurrentMemberBasicInfo(); + MembershipFee membershipFee = MembershipFeeRequestDto.toEntity(requestDto, memberInfo.getMemberId()); externalSendNotificationUseCase.sendNotificationToAdmins("새로운 회비 내역이 등록되었습니다."); + SlackMembershipFeeInfo membershipFeeInfo = SlackMembershipFeeInfo.create(membershipFee, memberInfo); + slackService.sendNewMembershipFeeNotification(membershipFeeInfo); return registerMembershipFeePort.save(membershipFee).getId(); } } diff --git a/src/main/java/page/clab/api/global/common/slack/application/SlackService.java b/src/main/java/page/clab/api/global/common/slack/application/SlackService.java index 3d2333411..84040d763 100644 --- a/src/main/java/page/clab/api/global/common/slack/application/SlackService.java +++ b/src/main/java/page/clab/api/global/common/slack/application/SlackService.java @@ -5,12 +5,13 @@ import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; -import page.clab.api.global.common.slack.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; @@ -47,8 +48,8 @@ public void sendNewBoardNotification(SlackBoardInfo board) { eventPublisher.publishEvent(new NotificationEvent(this, executivesWebhookUrl, ExecutivesAlertType.NEW_BOARD, null, board)); } - public void sendNewMembershipFeeNotification() { - eventPublisher.publishEvent(new NotificationEvent(this, executivesWebhookUrl, ExecutivesAlertType.NEW_MEMBERSHIP_FEE, null, null)); + public void sendNewMembershipFeeNotification(SlackMembershipFeeInfo membershipFee) { + eventPublisher.publishEvent(new NotificationEvent(this, executivesWebhookUrl, ExecutivesAlertType.NEW_MEMBERSHIP_FEE, null, membershipFee)); } @EventListener(ContextRefreshedEvent.class) diff --git a/src/main/java/page/clab/api/global/common/slack/application/SlackServiceHelper.java b/src/main/java/page/clab/api/global/common/slack/application/SlackServiceHelper.java index 85b8d1f3e..346921c68 100644 --- a/src/main/java/page/clab/api/global/common/slack/application/SlackServiceHelper.java +++ b/src/main/java/page/clab/api/global/common/slack/application/SlackServiceHelper.java @@ -20,13 +20,14 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import page.clab.api.global.common.slack.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.AlertType; 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.config.SlackConfig; import page.clab.api.global.util.HttpReqResUtil; @@ -127,6 +128,10 @@ public List createBlocks(AlertType alertType, HttpServletRequest re return createBoardBlocks((SlackBoardInfo) additionalData); } break; + case NEW_MEMBERSHIP_FEE: + if (additionalData instanceof SlackMembershipFeeInfo) { + return createMembershipFeeBlocks((SlackMembershipFeeInfo) additionalData); + } default: log.error("Unknown alert type: {}", alertType); return List.of(); @@ -220,6 +225,20 @@ private List createBoardBlocks(SlackBoardInfo board) { return blocks; } + private List createMembershipFeeBlocks(SlackMembershipFeeInfo additionalData) { + String username = additionalData.getMemberId() + " " + additionalData.getMemberName(); + + return Arrays.asList( + section(section -> section.text(markdownText(":dollar: *New Membership Fee*"))), + section(section -> section.fields(Arrays.asList( + markdownText("*User:*\n" + username), + markdownText("*Category:*\n" + additionalData.getCategory()), + markdownText("*Amount:*\n" + additionalData.getAmount() + "원") + ))), + section(section -> section.text(markdownText("*Content:*\n" + additionalData.getContent()))) + ); + } + private List createServerStartBlocks() { String osInfo = System.getProperty("os.name") + " " + System.getProperty("os.version"); String jdkVersion = System.getProperty("java.version"); diff --git a/src/main/java/page/clab/api/global/common/slack/domain/SlackMembershipFeeInfo.java b/src/main/java/page/clab/api/global/common/slack/domain/SlackMembershipFeeInfo.java new file mode 100644 index 000000000..02461c71d --- /dev/null +++ b/src/main/java/page/clab/api/global/common/slack/domain/SlackMembershipFeeInfo.java @@ -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(); + } +}