Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAC-376 feat : 선배 인증 요청 슬랙 웹훅 추가 #269

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +73,8 @@ class SeniorManageUseTypeTest {
private UserUtils userUtils;
@Mock
private SeniorUtils seniorUtils;
@Mock
private SlackCertificationMessage slackCertificationMessage;
@InjectMocks
private SeniorManageUseCase seniorManageUseCase;

Expand Down
Loading