diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthResponse.java b/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthResponse.java new file mode 100644 index 00000000..0a5bd226 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthResponse.java @@ -0,0 +1,3 @@ +package com.postgraduate.domain.auth.application.dto.res; + +public interface AuthResponse {} diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthUserResponse.java b/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthUserResponse.java index 02d65804..694f8c74 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthUserResponse.java +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/res/AuthUserResponse.java @@ -2,7 +2,7 @@ import com.postgraduate.domain.user.domain.entity.User; -public record AuthUserResponse(User user, Long socialId) { +public record AuthUserResponse(User user, Long socialId) implements AuthResponse{ public AuthUserResponse(Long socialId) { this(null, socialId); } diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java b/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java index f57e085b..a4e85fc4 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/res/JwtTokenResponse.java @@ -3,4 +3,4 @@ import com.postgraduate.domain.user.domain.entity.constant.Role; public record JwtTokenResponse(String accessToken, int accessExpiration, - String refreshToken, int refreshExpiration, Role role) {} + String refreshToken, int refreshExpiration, Role role) implements AuthResponse{} 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 fe18a551..7611c6d6 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 @@ -33,9 +33,7 @@ @RequiredArgsConstructor public class SignUpUseCase { @Value("${profile.user}") - private String userProfile; - @Value("${profile.senior}") - private String seniorProfile; + private String profile; private final SalarySaveService salarySaveService; private final UserSaveService userSaveService; @@ -48,7 +46,7 @@ public class SignUpUseCase { public User userSignUp(SignUpRequest request) { userUtils.checkPhoneNumber(request.phoneNumber()); - User user = UserMapper.mapToUser(request, userProfile); + User user = UserMapper.mapToUser(request, profile); Wish wish = WishMapper.mapToWish(user, request); wishSaveService.save(wish); userSaveService.save(user); @@ -58,7 +56,7 @@ public User userSignUp(SignUpRequest request) { public User seniorSignUp(SeniorSignUpRequest request) { seniorUtils.checkKeyword(request.keyword()); userUtils.checkPhoneNumber(request.phoneNumber()); - User user = UserMapper.mapToUser(request, seniorProfile); + User user = UserMapper.mapToUser(request, profile); userSaveService.save(user); Senior senior = SeniorMapper.mapToSenior(user, request); seniorSaveService.saveSenior(senior); @@ -69,7 +67,7 @@ public User seniorSignUp(SeniorSignUpRequest request) { public User changeSenior(User user, SeniorChangeRequest changeRequest) { seniorUtils.checkKeyword(changeRequest.keyword()); - Senior senior = SeniorMapper.mapToSenior(user, changeRequest); //todo : 예외 처리 + Senior senior = SeniorMapper.mapToSenior(user, changeRequest); seniorSaveService.saveSenior(senior); user = userGetService.byUserId(user.getUserId()); userUpdateService.updateRole(user, Role.SENIOR); diff --git a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java index d55c3602..50ea6c8b 100644 --- a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java @@ -1,6 +1,7 @@ package com.postgraduate.domain.auth.presentation; import com.postgraduate.domain.auth.application.dto.req.*; +import com.postgraduate.domain.auth.application.dto.res.AuthResponse; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse; import com.postgraduate.domain.auth.application.usecase.oauth.SelectOauth; @@ -35,7 +36,7 @@ public class AuthController { @PostMapping("/login/{provider}") @Operation(summary = "소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).") - public ResponseDto authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { + public ResponseDto authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getUser(request); if (authUser.user() == null) @@ -46,7 +47,7 @@ public ResponseDto authLogin(@RequestBody @Valid CodeRequest request, @PathVa @PostMapping("/dev/login/{provider}") @Operation(summary = "개발용 소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).") - public ResponseDto authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { + public ResponseDto authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getDevUser(request); if (authUser.user() == null) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java index e1935ae9..762dd833 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java @@ -20,8 +20,8 @@ public class CheckIsMyMentoringUseCase { public Mentoring byUser(User user, Long mentoringId) { Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); if (!mentoring.getUser().isEqual(user)) { - log.warn("userId = {}", user.getUserId()); - log.warn("mentoring.getUserId = {}", mentoring.getUser().getUserId()); + log.error("userId = {}", user.getUserId()); + log.error("mentoring.getUserId = {}", mentoring.getUser().getUserId()); throw new PermissionDeniedException(); } return mentoring; @@ -30,8 +30,8 @@ public Mentoring byUser(User user, Long mentoringId) { public Mentoring bySenior(Senior senior, Long mentoringId) { Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); if (!mentoring.getSenior().isEqual(senior)) { - log.warn("userId = {}", senior.getSeniorId()); - log.warn("mentoring.getUserId = {}", mentoring.getSenior().getSeniorId()); + log.error("userId = {}", senior.getSeniorId()); + log.error("mentoring.getUserId = {}", mentoring.getSenior().getSeniorId()); throw new PermissionDeniedException(); } return mentoring; 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 45d40a0b..f5492354 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 @@ -13,7 +13,6 @@ import com.postgraduate.domain.mentoring.exception.MentoringDateException; import com.postgraduate.domain.mentoring.exception.MentoringNotExpectedException; import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException; -import com.postgraduate.domain.mentoring.exception.MentoringPresentException; import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.payment.domain.service.PaymentGetService; @@ -42,7 +41,6 @@ @Service @Slf4j -@Transactional @RequiredArgsConstructor public class MentoringManageUseCase { private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; @@ -59,10 +57,10 @@ public class MentoringManageUseCase { private final PaymentGetService paymentGetService; private final SlackErrorMessage slackErrorMessage; + @Transactional public boolean applyMentoringWithPayment(User user, MentoringApplyRequest request) { Payment payment = paymentGetService.byUserAndOrderId(user, request.orderId()); - if (mentoringGetService.byPayment(payment).isPresent()) - throw new MentoringPresentException(); + mentoringGetService.byPayment(payment); try { String[] dates = request.date().split(","); if (dates.length != 3) @@ -76,6 +74,8 @@ public boolean applyMentoringWithPayment(User user, MentoringApplyRequest reques return false; } } + + @Transactional public void updateCancel(User user, Long mentoringId) { Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId); if (mentoring.getStatus() != WAITING) @@ -85,6 +85,8 @@ public void updateCancel(User user, Long mentoringId) { mentoringUpdateService.updateStatus(mentoring, CANCEL); } + + @Transactional public void updateDone(User user, Long mentoringId) { Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId); if (mentoring.getStatus() != EXPECTED) @@ -94,6 +96,8 @@ public void updateDone(User user, Long mentoringId) { mentoringUpdateService.updateStatus(mentoring, DONE); } + + @Transactional public void updateRefuse(User user, Long mentoringId, MentoringRefuseRequest request) { Senior senior = seniorGetService.byUser(user); Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(senior, mentoringId); @@ -106,6 +110,8 @@ public void updateRefuse(User user, Long mentoringId, MentoringRefuseRequest req mentoringUpdateService.updateStatus(mentoring, REFUSE); } + + @Transactional public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest dateRequest) { Senior senior = seniorGetService.byUser(user); Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(senior, mentoringId); @@ -117,30 +123,37 @@ public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest return account.isPresent(); } + + @Transactional public void delete(User user, Long mentoringId) { Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId); mentoringDeleteService.deleteMentoring(mentoring); } - @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") + @Scheduled(cron = "0 17 05 * * *", zone = "Asia/Seoul") public void updateAutoCancel() { LocalDateTime now = LocalDateTime.now() .toLocalDate() .atStartOfDay(); List waitingMentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now); - waitingMentorings.forEach(mentoring -> { - try { - mentoringUpdateService.updateStatus(mentoring, CANCEL); - Refuse refuse = RefuseMapper.mapToRefuse(mentoring); - refuseSaveService.save(refuse); - paymentManageUseCase.refundPayByUser(mentoring.getUser(), mentoring.getPayment().getOrderId()); - } catch (Exception ex) { - slackErrorMessage.sendSlackError(mentoring, ex); - } - }); + waitingMentorings.forEach(this::updateCancelWithAuto); //TODO : 알림 보내거나 나머지 작업 } + @Transactional + public void updateCancelWithAuto(Mentoring mentoring) { + try { + mentoringUpdateService.updateStatus(mentoring, CANCEL); + Refuse refuse = RefuseMapper.mapToRefuse(mentoring); + refuseSaveService.save(refuse); + paymentManageUseCase.refundPayByUser(mentoring.getUser(), mentoring.getPayment().getOrderId()); + log.info("mentoringId : {} 자동 취소", mentoring.getMentoringId()); + } catch (Exception ex) { + log.error("mentoringId : {} 자동 취소 실패", mentoring.getMentoringId()); + slackErrorMessage.sendSlackError(mentoring, ex); + } + } + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") public void updateAutoDone() { List expectedMentorings = mentoringGetService.byStatus(EXPECTED); @@ -153,16 +166,21 @@ public void updateAutoDone() { return false; } }) - .forEach(mentoring -> { - try { - mentoringUpdateService.updateStatus(mentoring, DONE); - Senior senior = mentoring.getSenior(); - Salary salary = salaryGetService.bySenior(senior); - salaryUpdateService.updateTotalAmount(salary); - } catch (Exception ex) { - slackErrorMessage.sendSlackError(mentoring, ex); - } - }); + .forEach(this::updateDoneWithAuto); //TODO : 알림 보내거나 나머지 작업 } + + @Transactional + public void updateDoneWithAuto(Mentoring mentoring) { + try { + mentoringUpdateService.updateStatus(mentoring, DONE); + Senior senior = mentoring.getSenior(); + Salary salary = salaryGetService.bySenior(senior); + salaryUpdateService.updateTotalAmount(salary); + log.info("mentoringId : {} 자동 완료", mentoring.getMentoringId()); + } catch (Exception ex) { + slackErrorMessage.sendSlackError(mentoring, ex); + log.error("mentoringId : {} 자동 완료 실패", mentoring.getMentoringId()); + } + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java index 74a98ba3..d1795dc0 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java @@ -4,6 +4,7 @@ import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; import com.postgraduate.domain.mentoring.exception.MentoringNotFoundException; +import com.postgraduate.domain.mentoring.exception.MentoringPresentException; import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; @@ -15,7 +16,6 @@ import java.time.LocalDateTime; import java.util.List; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -24,8 +24,11 @@ public class MentoringGetService { private final MentoringRepository mentoringRepository; - public Optional byPayment(Payment payment) { - return mentoringRepository.findByPayment(payment); + public void byPayment(Payment payment) { + mentoringRepository.findByPayment(payment) + .ifPresent(mentoring -> { + throw new MentoringPresentException(); + }); } public List byUser(User user, Status status) { diff --git a/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java b/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java index b5d86d71..e7f861cd 100644 --- a/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java +++ b/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java @@ -29,23 +29,23 @@ public static UserInfoResponse mapToInfo(User user) { ); } - public static User mapToUser(SignUpRequest request, String userProfile) { + public static User mapToUser(SignUpRequest request, String profile) { return User.builder() .socialId(request.socialId()) .nickName(request.nickName()) .phoneNumber(request.phoneNumber()) .marketingReceive(request.marketingReceive()) - .profile(userProfile) + .profile(profile) .build(); } - public static User mapToUser(SeniorSignUpRequest request, String seniorProfile) { + public static User mapToUser(SeniorSignUpRequest request, String profile) { return User.builder() .socialId(request.socialId()) .nickName(request.nickName()) .phoneNumber(request.phoneNumber()) .marketingReceive(request.marketingReceive()) - .profile(seniorProfile) + .profile(profile) .role(SENIOR) .build(); } diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java index e8194bbe..d777c72e 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java @@ -121,8 +121,6 @@ void applyMentoring() { given(paymentGetService.byUserAndOrderId(any(), any())) .willReturn(payment); - given(mentoringGetService.byPayment(payment)) - .willReturn(Optional.ofNullable(null)); given(payment.getSalary()) .willReturn(salary); given(salary.getSenior())