From 1009006ba25b3c46ef7743ec92f452b43e1edc48 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 23 May 2024 01:45:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?RAC-376=20feat=20:=20=EC=84=A0=EB=B0=B0=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=9A=94=EC=B2=AD=EC=8B=9C=20=EC=8A=AC?= =?UTF-8?q?=EB=9E=99=20=EC=9B=B9=ED=9B=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/SeniorManageUseCase.java | 3 ++ .../slack/SlackCertificationMessage.java | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/com/postgraduate/global/slack/SlackCertificationMessage.java diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java index 10fbb2c5..09dffa69 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java @@ -25,6 +25,7 @@ import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.service.UserUpdateService; import com.postgraduate.global.config.security.util.EncryptorUtils; +import com.postgraduate.global.slack.SlackCertificationMessage; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -55,10 +56,12 @@ public class SeniorManageUseCase { private final EncryptorUtils encryptorUtils; private final UserUtils userUtils; private final SeniorUtils seniorUtils; + private final SlackCertificationMessage slackCertificationMessage; public void updateCertification(User user, SeniorCertificationRequest certificationRequest) { Senior senior = seniorGetService.byUser(user); seniorUpdateService.updateCertification(senior, certificationRequest.certification()); + slackCertificationMessage.sendCertification(senior); } public SeniorProfileUpdateResponse signUpProfile(User user, SeniorProfileRequest profileRequest) { diff --git a/src/main/java/com/postgraduate/global/slack/SlackCertificationMessage.java b/src/main/java/com/postgraduate/global/slack/SlackCertificationMessage.java new file mode 100644 index 00000000..0438c243 --- /dev/null +++ b/src/main/java/com/postgraduate/global/slack/SlackCertificationMessage.java @@ -0,0 +1,53 @@ +package com.postgraduate.global.slack; + +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.user.domain.entity.User; +import com.slack.api.Slack; +import com.slack.api.model.Attachment; +import com.slack.api.webhook.Payload; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.List; + +import static com.postgraduate.global.slack.SlackUtils.generateSlackField; + +@Slf4j +@RequiredArgsConstructor +@Component +public class SlackCertificationMessage { + private final Slack slackClient = Slack.getInstance(); + + @Value("${slack.certification_url}") + private String certificationUrl; + + public void sendCertification(Senior senior) { + try { + slackClient.send(certificationUrl, Payload.builder() + .text("선배 인증 요청이 들어왔습니다!") + .attachments( + List.of(generateCertificationAttachment(senior)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + private Attachment generateCertificationAttachment(Senior senior) { + User user = senior.getUser(); + return Attachment.builder() + .color("2FC4B2") + .title("선배 인증 요청") + .fields(List.of( + generateSlackField("선배 닉네임 : ", user.getNickName()), + generateSlackField("선배 대학원 : ", senior.getInfo().getPostgradu()), + generateSlackField("선배 연구실 : ", senior.getInfo().getLab()), + generateSlackField("선배 교수 : " , senior.getInfo().getProfessor()) + )) + .build(); + } +} From f74b748aff83c70274566f81666c1ab5d7086cb4 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 23 May 2024 01:51:05 +0900 Subject: [PATCH 2/2] =?UTF-8?q?RAC-376=20test=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20Mock=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../senior/application/usecase/SeniorManageUseTypeTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseTypeTest.java b/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseTypeTest.java index d6ea86c1..8eb12465 100644 --- a/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseTypeTest.java +++ b/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseTypeTest.java @@ -25,6 +25,7 @@ import com.postgraduate.domain.user.domain.service.UserUpdateService; import com.postgraduate.domain.user.exception.PhoneNumberException; import com.postgraduate.global.config.security.util.EncryptorUtils; +import com.postgraduate.global.slack.SlackCertificationMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -72,6 +73,8 @@ class SeniorManageUseTypeTest { private UserUtils userUtils; @Mock private SeniorUtils seniorUtils; + @Mock + private SlackCertificationMessage slackCertificationMessage; @InjectMocks private SeniorManageUseCase seniorManageUseCase;