Skip to content

Commit

Permalink
Merge pull request #221 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ywj9811 authored Apr 11, 2024
2 parents ffd9b76 + 63a169d commit 2aa3568
Show file tree
Hide file tree
Showing 59 changed files with 748 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class AdminMentoringUseCase {
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;

@Transactional(readOnly = true)
public MentoringManageResponse seniorMentorings(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
List<Mentoring> mentorings = mentoringGetService.bySeniorId(seniorId);
Expand All @@ -47,6 +48,7 @@ public MentoringManageResponse seniorMentorings(Long seniorId) {
return new MentoringManageResponse(mentoringInfos, seniorInfo);
}

@Transactional(readOnly = true)
public MentoringManageResponse userMentoringInfos(Long userId) {
User user = userGetService.byUserId(userId);
List<Mentoring> mentorings = mentoringGetService.byUserId(userId);
Expand All @@ -64,7 +66,7 @@ public void refundMentoring(User user, Long mentoringId) {
if (mentoring.getStatus() == DONE) {
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.minusTotalAmount(salary);
salaryUpdateService.minusTotalAmount(salary, mentoring.calculateForSenior());
}
mentoringUpdateService.updateCancel(mentoring);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class AdminPaymentUseCase {
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;

@Transactional(readOnly = true)
public List<PaymentInfo> paymentInfos() {
List<Payment> all = paymentGetService.all();
return all.stream()
Expand All @@ -44,6 +45,7 @@ public List<PaymentInfo> paymentInfos() {
.toList();
}

@Transactional(readOnly = true)
public MentoringWithPaymentResponse paymentMentoringInfo(Long paymentId) {
Payment payment = paymentGetService.byId(paymentId);
Mentoring mentoring = mentoringGetService.byPayment(payment);
Expand All @@ -58,7 +60,7 @@ public void refundPayment(User user, Long paymentId) {
mentoringUpdateService.updateCancel(mentoring);
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.minusTotalAmount(salary);
salaryUpdateService.minusTotalAmount(salary, mentoring.calculateForSenior());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AdminSalaryUseCase {
private final SalaryUpdateService salaryUpdateService;
private final EncryptorUtils encryptorUtils;

@Transactional(readOnly = true)
public List<SalaryInfoWithOutId> salaryInfos() {
List<Salary> all = salaryGetService.findAll();
return all.stream()
Expand All @@ -40,6 +41,7 @@ public List<SalaryInfoWithOutId> salaryInfos() {
.toList();
}

@Transactional(readOnly = true)
public SalaryInfoWithOutId seniorSalary(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
Salary salary = salaryGetService.bySenior(senior);
Expand All @@ -55,6 +57,7 @@ public void salaryDone(Long salaryId) {
salaryUpdateService.updateDone(salary);
}

@Transactional(readOnly = true)
public List<UnSettledSalaryInfo> unSettledSalaryInfo() {
List<Salary> salaries = salaryGetService.allByNotDone();
return salaries.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.postgraduate.domain.senior.exception.SeniorCertificationException;
import com.postgraduate.domain.wish.domain.entity.Wish;
import com.postgraduate.domain.wish.domain.service.WishGetService;
import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -29,7 +30,9 @@ public class AdminSeniorUseCase {
private final SeniorUpdateService seniorUpdateService;
private final SalaryGetService salaryGetService;
private final WishGetService wishGetService;
private final BizppurioSeniorMessage bizppurioSeniorMessage;

@Transactional(readOnly = true)
public List<SeniorInfo> allSenior() {
List<Senior> seniors = seniorGetService.allSenior();
return seniors.stream()
Expand All @@ -41,6 +44,7 @@ public List<SeniorInfo> allSenior() {
.toList();
}

@Transactional(readOnly = true)
public CertificationDetailsResponse getCertification(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
if (senior.getStatus() == APPROVE)
Expand All @@ -52,11 +56,13 @@ public CertificationDetailsResponse getCertification(Long seniorId) {
public void updateNotApprove(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
seniorUpdateService.certificationUpdateNotApprove(senior);
bizppurioSeniorMessage.certificationDenied(senior.getUser());
}

public void updateApprove(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
seniorUpdateService.certificationUpdateApprove(senior);
bizppurioSeniorMessage.certificationApprove(senior.getUser());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ public class AdminUserUseCase {
private final WishGetService wishGetService;
private final WishUpdateService wishUpdateService;

@Transactional(readOnly = true)
public List<UserInfo> userInfos() {
List<Wish> all = wishGetService.all();
return all.stream()
.map(AdminSsrMapper::mapToUserInfo)
.toList();
}

@Transactional(readOnly = true)
public WishResponse wishInfo(Long userId) {
Wish wish = wishGetService.byUserId(userId);
return mapToWishResponse(wish);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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.bizppurio.usecase.BizppurioSeniorMessage;
import com.postgraduate.global.slack.SlackSignUpMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -44,6 +45,7 @@ public class SignUpUseCase {
private final SlackSignUpMessage slackSignUpMessage;
private final UserUtils userUtils;
private final SeniorUtils seniorUtils;
private final BizppurioSeniorMessage bizppurioSeniorMessage;

public User userSignUp(SignUpRequest request) {
userUtils.checkPhoneNumber(request.phoneNumber());
Expand All @@ -63,8 +65,11 @@ public User seniorSignUp(SeniorSignUpRequest request) {
Senior senior = SeniorMapper.mapToSenior(user, request);
seniorSaveService.saveSenior(senior);
Salary salary = SalaryMapper.mapToSalary(senior, getSalaryDate());
Salary nextSalary = SalaryMapper.mapToSalary(senior, getSalaryDate().plusDays(7));
salarySaveService.save(salary);
salarySaveService.save(nextSalary);
slackSignUpMessage.sendSeniorSignUp(senior);
bizppurioSeniorMessage.signUp(user);
return senior.getUser();
}

Expand All @@ -75,8 +80,11 @@ public User changeSenior(User user, SeniorChangeRequest changeRequest) {
user = userGetService.byUserId(user.getUserId());
userUpdateService.userToSeniorRole(user);
Salary salary = SalaryMapper.mapToSalary(senior, getSalaryDate());
Salary nextSalary = SalaryMapper.mapToSalary(senior, getSalaryDate().plusDays(7));
salarySaveService.save(salary);
salarySaveService.save(nextSalary);
slackSignUpMessage.sendSeniorSignUp(senior);
bizppurioSeniorMessage.signUp(user);
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;

@RequiredArgsConstructor
@Service
@Transactional
@Slf4j
public class KakaoAccessTokenUseCase {

@Value("${app-id.kakao}")
private String APP_ID;
private String appId;
@Value("${kakao.redirect-uri}")
private String REDIRECT_URI;
private String redirectUrl;
@Value("${kakao.dev-redirect-uri}")
private String DEV_REDIRECT_URI;
private String devRedirectUrl;
@Value("${kakao.authorization-grant-type}")
private String AUTHORIZATION_GRANT_TYPE;
private String authorizationGrantType;
private final WebClient webClient;

private static final String KAKAO_TOKEN_URI = "https://kauth.kakao.com/oauth/token";
Expand Down Expand Up @@ -71,9 +69,9 @@ public KakaoUserInfoResponse getDevAccessToken (CodeRequest codeRequest) {

private MultiValueMap<String, String> getRequestBody(String code) {
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE);
requestBody.add("client_id", APP_ID);
requestBody.add("redirect_uri", REDIRECT_URI);
requestBody.add("grant_type", authorizationGrantType);
requestBody.add("client_id", appId);
requestBody.add("redirect_uri", redirectUrl);
requestBody.add("code", code);
return requestBody;
}
Expand All @@ -94,9 +92,9 @@ private KakaoUserInfoResponse getUserInfo(String accessToken) {

private MultiValueMap<String, String> getDevRequestBody(String code) {
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE);
requestBody.add("client_id", APP_ID);
requestBody.add("redirect_uri", DEV_REDIRECT_URI);
requestBody.add("grant_type", authorizationGrantType);
requestBody.add("client_id", appId);
requestBody.add("redirect_uri", devRedirectUrl);
requestBody.add("code", code);
return requestBody;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Service
@RequiredArgsConstructor
@Transactional
@Transactional(readOnly = true)
public class KakaoSignInUseCase implements SignInUseCase {
private final KakaoAccessTokenUseCase kakaoTokenUseCase;
private final UserGetService userGetService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.postgraduate.domain.payment.domain.service.PaymentGetService;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -27,6 +29,8 @@ public class MentoringApplyingUseCase {
private final MentoringGetService mentoringGetService;
private final MentoringSaveService mentoringSaveService;
private final AccountGetService accountGetService;
private final BizppurioSeniorMessage bizppurioSeniorMessage;
private final BizppurioJuniorMessage bizppurioJuniorMessage;

public ApplyingResponse applyMentoringWithPayment(User user, MentoringApplyRequest request) {
Payment payment = paymentGetService.byUserAndOrderId(user, request.orderId());
Expand All @@ -38,6 +42,8 @@ public ApplyingResponse applyMentoringWithPayment(User user, MentoringApplyReque
Mentoring mentoring = MentoringMapper.mapToMentoring(user, senior, payment, request);
mentoringSaveService.save(mentoring);
Optional<Account> account = accountGetService.bySenior(senior);
bizppurioJuniorMessage.mentoringApply(user);
bizppurioSeniorMessage.mentoringApply(senior.getUser());
return new ApplyingResponse(account.isPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage;
import com.postgraduate.global.slack.SlackErrorMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,6 +35,7 @@
import java.util.Optional;

import static com.postgraduate.domain.refuse.application.mapper.RefuseMapper.mapToRefuse;
import static java.time.LocalDateTime.now;

@Service
@Slf4j
Expand All @@ -49,6 +52,8 @@ public class MentoringManageUseCase {
private final PaymentManageUseCase paymentManageUseCase;
private final SlackErrorMessage slackErrorMessage;
private final MentoringApplyingUseCase mentoringApplyingUseCase;
private final BizppurioJuniorMessage bizppurioJuniorMessage;
private final BizppurioSeniorMessage bizppurioSeniorMessage;

public ApplyingResponse applyMentoring(User user, MentoringApplyRequest request) {
try {
Expand Down Expand Up @@ -78,7 +83,7 @@ public void updateCancel(User user, Long mentoringId) {
public void updateDone(User user, Long mentoringId) {
Mentoring mentoring = mentoringGetService.byIdAndUserAndExpected(mentoringId, user);
Salary salary = salaryGetService.bySenior(mentoring.getSenior());
salaryUpdateService.plusTotalAmount(salary);
salaryUpdateService.plusTotalAmount(salary, mentoring.calculateForSenior());
mentoringUpdateService.updateDone(mentoring, salary);
}

Expand All @@ -92,6 +97,7 @@ public void updateRefuse(User user, Long mentoringId, MentoringRefuseRequest req
Payment payment = mentoring.getPayment();
paymentManageUseCase.refundPayBySenior(senior, payment.getOrderId());
mentoringUpdateService.updateRefuse(mentoring);
bizppurioJuniorMessage.mentoringRefuse(mentoring.getUser());
}


Expand All @@ -101,17 +107,19 @@ public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest
Mentoring mentoring = mentoringGetService.byIdAndSeniorAndWaiting(mentoringId, senior);
mentoringUpdateService.updateExpected(mentoring, dateRequest.date());
Optional<Account> account = accountGetService.bySenior(senior);
String time = mentoringDateToTime(dateRequest.date());
bizppurioSeniorMessage.mentoringAccept(senior, time);
bizppurioJuniorMessage.mentoringAccept(mentoring.getUser(), senior, time);
return account.isPresent();
}

@Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul")
public void updateAutoCancel() {
LocalDateTime now = LocalDateTime.now()
LocalDateTime now = now()
.toLocalDate()
.atStartOfDay();
List<Mentoring> waitingMentorings = mentoringGetService.byWaitingAndCreatedAt(now);
waitingMentorings.forEach(mentoringRenewalUseCase::updateCancelWithAuto);
//TODO : μ•Œλ¦Ό λ³΄λ‚΄κ±°λ‚˜ λ‚˜λ¨Έμ§€ μž‘μ—…
}

@Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul")
Expand All @@ -127,6 +135,28 @@ public void updateAutoDone() {
}
})
.forEach(mentoringRenewalUseCase::updateDoneWithAuto);
//TODO : μ•Œλ¦Ό λ³΄λ‚΄κ±°λ‚˜ λ‚˜λ¨Έμ§€ μž‘μ—…
}

// @Scheduled(fixedDelay = 1000*60*10)
// @Transactional
// public void sendFinishMessage() {
// List<Mentoring> expectedMentorings = mentoringGetService.byExpected();
// expectedMentorings.stream()
// .filter(mentoring -> {
// LocalDateTime mentoringDate = DateUtils.stringToLocalDateTime(mentoring.getDate());
// LocalDateTime finishTime = mentoringDate.plusMinutes(mentoring.getTerm());
// if (now().isAfter(finishTime))
// return true;
// return false;
// })
// .forEach(mentoring -> {
// bizppurioJuniorMessage.mentoringFinish(mentoring.getUser());
// bizppurioSeniorMessage.mentoringFinish(mentoring.getSenior().getUser());
// });
// }

private String mentoringDateToTime(String date) {
String[] split = date.split("-");
return split[1] + "μ›” " + split[2] + "일 " + split[3] + "μ‹œ " + split[4] + "λΆ„";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.domain.salary.domain.service.SalaryUpdateService;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage;
import com.postgraduate.global.slack.SlackErrorMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -31,6 +32,7 @@ public class MentoringRenewalUseCase {
private final SalaryUpdateService salaryUpdateService;
private final SalaryGetService salaryGetService;
private final SlackErrorMessage slackErrorMessage;
private final BizppurioJuniorMessage bizppurioJuniorMessage;

public void updateCancelWithAuto(Mentoring mentoring) {
try {
Expand All @@ -40,6 +42,7 @@ public void updateCancelWithAuto(Mentoring mentoring) {
Refuse refuse = mapToRefuse(mentoring);
refuseSaveService.save(refuse);
log.info("mentoringId : {} μžλ™ μ·¨μ†Œ", mentoring.getMentoringId());
bizppurioJuniorMessage.mentoringRefuse(mentoring.getUser());
} catch (Exception ex) {
log.error("mentoringId : {} μžλ™ μ·¨μ†Œ μ‹€νŒ¨", mentoring.getMentoringId());
log.error(ex.getMessage());
Expand All @@ -53,7 +56,7 @@ public void updateDoneWithAuto(Mentoring mentoring) {
Mentoring doneMentoring = mentoringGetService.byMentoringIdWithLazy(mentoring.getMentoringId());
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.plusTotalAmount(salary);
salaryUpdateService.plusTotalAmount(salary, doneMentoring.calculateForSenior());
mentoringUpdateService.updateDone(doneMentoring, salary);
log.info("mentoringId : {} μžλ™ μ™„λ£Œ", mentoring.getMentoringId());
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static java.time.Duration.between;

@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class MentoringSeniorInfoUseCase {
private final MentoringGetService mentoringGetService;
Expand Down
Loading

0 comments on commit 2aa3568

Please sign in to comment.