Skip to content

Commit

Permalink
Merge pull request #207 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ywj9811 authored Apr 2, 2024
2 parents 20c2341 + 748c7ae commit 01c5cff
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}

Expand All @@ -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();
}

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Mentoring> expectedMentorings = mentoringGetService.byExpected();
expectedMentorings.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public List<Salary> findAllByDone() {
.fetchJoin()
.join(senior.user, user)
.fetchJoin()
.where(salary.totalAmount.gt(0))
.orderBy(salary.salaryDoneDate.desc())
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public record SeniorSearchResponse(
String postgradu,
String major,
String lab,
String professor,
String[] keyword
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> fieldNames = Field.fieldNames();
this.keyword = request.keyword();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,8 @@ class SignUpUseCaseTest {
private UserUtils userUtils;
@Mock
private SeniorUtils seniorUtils;
@Mock
private SlackSignUpMessage slackSignUpMessage;
@InjectMocks
private SignUpUseCase signUpUseCase;

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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +46,8 @@ class PaymentManageUseCaseTest {
private UserGetService userGetService;
@Mock
private WebClient webClient;
@Mock
private SlackPaymentMessage slackPaymentMessage;
@InjectMocks
private PaymentManageUseCase paymentManageUseCase;

Expand Down

0 comments on commit 01c5cff

Please sign in to comment.