diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java index f9a9bef2..7daa1208 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java @@ -14,13 +14,13 @@ import com.postgraduate.domain.user.application.mapper.UserMapper; import com.postgraduate.domain.user.application.utils.UserUtils; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.domain.service.UserGetService; import com.postgraduate.domain.user.domain.service.UserSaveService; import com.postgraduate.domain.user.domain.service.UserUpdateService; import com.postgraduate.domain.wish.application.mapper.WishMapper; import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.service.WishSaveService; +import com.postgraduate.global.slack.SlackSignUpMessage; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -41,6 +41,7 @@ public class SignUpUseCase { private final UserGetService userGetService; private final WishSaveService wishSaveService; private final SeniorSaveService seniorSaveService; + private final SlackSignUpMessage slackSignUpMessage; private final UserUtils userUtils; private final SeniorUtils seniorUtils; @@ -50,6 +51,7 @@ public User userSignUp(SignUpRequest request) { Wish wish = WishMapper.mapToWish(user, request); wishSaveService.save(wish); userSaveService.save(user); + slackSignUpMessage.sendJuniorSignUp(user, wish); return user; } @@ -62,6 +64,7 @@ public User seniorSignUp(SeniorSignUpRequest request) { seniorSaveService.saveSenior(senior); Salary salary = SalaryMapper.mapToSalary(senior, getSalaryDate()); salarySaveService.save(salary); + slackSignUpMessage.sendSeniorSignUp(senior); return senior.getUser(); } @@ -73,11 +76,13 @@ public User changeSenior(User user, SeniorChangeRequest changeRequest) { userUpdateService.userToSeniorRole(user); Salary salary = SalaryMapper.mapToSalary(senior, getSalaryDate()); salarySaveService.save(salary); + slackSignUpMessage.sendSeniorSignUp(senior); return user; } public void changeUser(User user, UserChangeRequest changeRequest) { Wish wish = WishMapper.mapToWish(user, changeRequest); wishSaveService.save(wish); + slackSignUpMessage.sendJuniorSignUp(user, wish); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index 57c9e5d6..97646d62 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -52,8 +52,7 @@ public class MentoringManageUseCase { public ApplyingResponse applyMentoring(User user, MentoringApplyRequest request) { try { - ApplyingResponse applyingResponse = mentoringApplyingUseCase.applyMentoringWithPayment(user, request); - return applyingResponse; + return mentoringApplyingUseCase.applyMentoringWithPayment(user, request); } catch (PaymentNotFoundException ex) { log.error("결제건을 찾을 수 없습니다."); throw ex; @@ -115,7 +114,7 @@ public void updateAutoCancel() { //TODO : 알림 보내거나 나머지 작업 } - @Scheduled(fixedRate = 700000, zone = "Asia/Seoul") + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") public void updateAutoDone() { List expectedMentorings = mentoringGetService.byExpected(); expectedMentorings.stream() diff --git a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java index f37f70b4..d6a88772 100644 --- a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java @@ -14,6 +14,7 @@ import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.service.UserGetService; +import com.postgraduate.global.slack.SlackPaymentMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -58,6 +59,7 @@ public class PaymentManageUseCase { private final SeniorGetService seniorGetService; private final UserGetService userGetService; private final WebClient webClient; + private final SlackPaymentMessage slackPaymentMessage; public void savePay(PaymentResultRequest request) { if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) { @@ -72,6 +74,7 @@ public void savePay(PaymentResultRequest request) { Senior senior = seniorGetService.bySeniorNickName(seniorNickName); Payment payment = PaymentMapper.resultToPayment(senior, user, request); paymentSaveService.save(payment); + slackPaymentMessage.sendPayment(payment); } catch (Exception ex) { log.error("paymentError 발생 환불 진행 | errorMessage : {}", ex.getMessage()); Payment payment = PaymentMapper.resultToPayment(request); diff --git a/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java b/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java index a02d4ead..2badfa1f 100644 --- a/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java +++ b/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java @@ -119,6 +119,7 @@ public List findAllByDone() { .fetchJoin() .join(senior.user, user) .fetchJoin() + .where(salary.totalAmount.gt(0)) .orderBy(salary.salaryDoneDate.desc()) .fetch(); } diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java index 2fb19dcf..12ebbb2d 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java @@ -7,5 +7,6 @@ public record SeniorSearchResponse( String postgradu, String major, String lab, + String professor, String[] keyword ) {} diff --git a/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java b/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java index 58a1af55..dec027f1 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java +++ b/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java @@ -184,7 +184,7 @@ public static SeniorSearchResponse mapToSeniorSearch(Senior senior) { String[] keyword = Arrays.copyOf(allKeywords, Math.min(3, allKeywords.length)); return new SeniorSearchResponse(senior.getSeniorId(), user.getProfile(), user.getNickName(), - info.getPostgradu(), info.getMajor(), info.getLab(), + info.getPostgradu(), info.getMajor(), info.getLab(), info.getProfessor(), keyword); } diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java index 015551a7..ee2dfad0 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java @@ -46,7 +46,7 @@ public class Info { @Column(nullable = false, columnDefinition = "TEXT") private String totalInfo; // 모든 Info정보 String으로 가지는 컬럼 - 검색시 사용 - public void updateMyPage(SeniorMyPageProfileRequest request) { + protected void updateMyPage(SeniorMyPageProfileRequest request) { String[] fileds = request.field().split(","); Set fieldNames = Field.fieldNames(); this.keyword = request.keyword(); diff --git a/src/main/java/com/postgraduate/domain/user/domain/entity/User.java b/src/main/java/com/postgraduate/domain/user/domain/entity/User.java index c7da98b6..b078f240 100644 --- a/src/main/java/com/postgraduate/domain/user/domain/entity/User.java +++ b/src/main/java/com/postgraduate/domain/user/domain/entity/User.java @@ -70,13 +70,6 @@ public void updateDelete() { this.isDelete = true; } - public boolean isEqual(User user) { - if (user == null) - return false; - return user.getUserId() - .equals(this.userId); - } - public boolean isDelete() { return this.isDelete; } diff --git a/src/main/java/com/postgraduate/global/slack/SlackPaymentMessage.java b/src/main/java/com/postgraduate/global/slack/SlackPaymentMessage.java new file mode 100644 index 00000000..e0c105ed --- /dev/null +++ b/src/main/java/com/postgraduate/global/slack/SlackPaymentMessage.java @@ -0,0 +1,60 @@ +package com.postgraduate.global.slack; + +import com.postgraduate.domain.payment.domain.entity.Payment; +import com.postgraduate.domain.senior.domain.entity.Info; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.wish.domain.entity.Wish; +import com.postgraduate.domain.wish.domain.entity.constant.Status; +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.domain.wish.domain.entity.constant.Status.REJECTED; +import static com.postgraduate.global.slack.SlackUtils.generateSlackField; + +@Component +@RequiredArgsConstructor +@Slf4j +public class SlackPaymentMessage { + private final Slack slackClient = Slack.getInstance(); + + @Value("${slack.pay_url}") + private String paymentUrl; + + public void sendPayment(Payment payment) { + try { + slackClient.send(paymentUrl, Payload.builder() + .text("결제가 되었습니다!") + .attachments( + List.of(generatePaymentAttachment(payment)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + //attach 생성 -> Field를 리스트로 담자 + private Attachment generatePaymentAttachment(Payment payment) { + User user = payment.getUser(); + Senior senior = payment.getSenior(); + User seniorUser = senior.getUser(); + return Attachment.builder() + .color("2FC4B2") + .title("결제정보") + .fields(List.of( + generateSlackField("결제 금액 : ", String.valueOf(payment.getPay())), + generateSlackField("후배 닉네임 : ", user.getNickName()), + generateSlackField("선배 닉네임 : ", seniorUser.getNickName()) + )) + .build(); + } +} diff --git a/src/main/java/com/postgraduate/global/slack/SlackSignUpMessage.java b/src/main/java/com/postgraduate/global/slack/SlackSignUpMessage.java new file mode 100644 index 00000000..46918e4b --- /dev/null +++ b/src/main/java/com/postgraduate/global/slack/SlackSignUpMessage.java @@ -0,0 +1,93 @@ +package com.postgraduate.global.slack; + +import com.postgraduate.domain.senior.domain.entity.Info; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.wish.domain.entity.Wish; +import com.postgraduate.domain.wish.domain.entity.constant.Status; +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.domain.wish.domain.entity.constant.Status.REJECTED; +import static com.postgraduate.global.slack.SlackUtils.generateSlackField; + +@Component +@RequiredArgsConstructor +@Slf4j +public class SlackSignUpMessage { + private final Slack slackClient = Slack.getInstance(); + + @Value("${slack.junior_url}") + private String juniorUrl; + @Value("${slack.senior_url}") + private String seniorUrl; + + public void sendJuniorSignUp(User user, Wish wish) { + try { + slackClient.send(juniorUrl, Payload.builder() + .text("후배가 가입했습니다!") + .attachments( + List.of(generateJuniorSignUpAttachment(user, wish)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + public void sendSeniorSignUp(Senior senior) { + try { + slackClient.send(seniorUrl, Payload.builder() + .text("선배가 가입했습니다!") + .attachments( + List.of(generateSeniorSignUpAttachment(senior)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + //attach 생성 -> Field를 리스트로 담자 + private Attachment generateJuniorSignUpAttachment(User user, Wish wish) { + Status status = wish.getStatus(); + String wantMatching = status == REJECTED ? "X" : "O"; + return Attachment.builder() + .color("2FC4B2") + .title("가입한 후배 정보") + .fields(List.of( + generateSlackField("후배 닉네임 : ", user.getNickName()), + generateSlackField("후배 전화번호", user.getPhoneNumber()), + generateSlackField("후배 매칭희망 여부", wantMatching), + generateSlackField("후배 매칭희망 전공, 분야", wish.getMajor() + ", " + wish.getField()) + )) + .build(); + } + + private Attachment generateSeniorSignUpAttachment(Senior senior) { + User user = senior.getUser(); + Info info = senior.getInfo(); + return Attachment.builder() + .color("2FC4B2") + .title("가입한 선배 정보") + .fields(List.of( + generateSlackField("선배 닉네임 : ", user.getNickName()), + generateSlackField("선배 전화번호", user.getPhoneNumber()), + generateSlackField("선배 대학원", info.getPostgradu()), + generateSlackField("선배 랩실", info.getLab()), + generateSlackField("선배 교수님", info.getProfessor()), + generateSlackField("선배 전공", info.getMajor()), + generateSlackField("선배 분야", info.getField()), + generateSlackField("선배 키워드", info.getKeyword()) + )) + .build(); + } +} diff --git a/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCaseTest.java b/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCaseTest.java index 1ea43b64..8f5a7808 100644 --- a/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCaseTest.java @@ -19,6 +19,7 @@ import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.entity.constant.Status; import com.postgraduate.domain.wish.domain.service.WishSaveService; +import com.postgraduate.global.slack.SlackSignUpMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -59,6 +60,8 @@ class SignUpUseCaseTest { private UserUtils userUtils; @Mock private SeniorUtils seniorUtils; + @Mock + private SlackSignUpMessage slackSignUpMessage; @InjectMocks private SignUpUseCase signUpUseCase; diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 87681eb2..e5cf0c1e 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -14,6 +14,7 @@ import com.postgraduate.global.config.security.jwt.util.JwtUtils; import com.postgraduate.global.slack.SlackLogErrorMessage; import com.postgraduate.global.slack.SlackSalaryMessage; +import com.postgraduate.global.slack.SlackSignUpMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -63,6 +64,8 @@ class AuthControllerTest extends IntegrationTest { RedisRepository redisRepository; @MockBean private SlackLogErrorMessage slackLogErrorMessage; + @MockBean + private SlackSignUpMessage slackSignUpMessage; private User user; private final Long anonymousUserSocialId = 2L; @@ -71,6 +74,8 @@ void setUp() { user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); userRepository.save(user); doNothing().when(slackLogErrorMessage).sendSlackLog(any()); + doNothing().when(slackSignUpMessage).sendSeniorSignUp(any()); + doNothing().when(slackSignUpMessage).sendJuniorSignUp(any(), any()); } @Test diff --git a/src/test/java/com/postgraduate/domain/payment/usecase/PaymentManageUseCaseTest.java b/src/test/java/com/postgraduate/domain/payment/usecase/PaymentManageUseCaseTest.java index 8051607e..c45be42e 100644 --- a/src/test/java/com/postgraduate/domain/payment/usecase/PaymentManageUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/payment/usecase/PaymentManageUseCaseTest.java @@ -11,6 +11,7 @@ import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.service.UserGetService; +import com.postgraduate.global.slack.SlackPaymentMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -45,6 +46,8 @@ class PaymentManageUseCaseTest { private UserGetService userGetService; @Mock private WebClient webClient; + @Mock + private SlackPaymentMessage slackPaymentMessage; @InjectMocks private PaymentManageUseCase paymentManageUseCase;