Skip to content

Commit

Permalink
feat(Slack): 회비 요청에 대한 슬랙 알림 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee committed Aug 16, 2024
1 parent 2cf0b97 commit 400d35e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -127,6 +128,10 @@ public List<LayoutBlock> 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();
Expand Down Expand Up @@ -220,6 +225,20 @@ private List<LayoutBlock> createBoardBlocks(SlackBoardInfo board) {
return blocks;
}

private List<LayoutBlock> 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<LayoutBlock> createServerStartBlocks() {
String osInfo = System.getProperty("os.name") + " " + System.getProperty("os.version");
String jdkVersion = System.getProperty("java.version");
Expand Down
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();
}
}

0 comments on commit 400d35e

Please sign in to comment.