Skip to content

Commit

Permalink
Merge pull request #138 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
RAC-304 deploy : 운영 μ„œλ²„ 반영
  • Loading branch information
ywj9811 authored Mar 1, 2024
2 parents 5e11faf + 2cc201a commit 7bd0968
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.postgraduate.domain.auth.application.dto.res;

public interface AuthResponse {}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<AuthResponse> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) {
SignInUseCase signInUseCase = selectOauth.selectSignIn(provider);
AuthUserResponse authUser = signInUseCase.getUser(request);
if (authUser.user() == null)
Expand All @@ -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<AuthResponse> authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) {
SignInUseCase signInUseCase = selectOauth.selectSignIn(provider);
AuthUserResponse authUser = signInUseCase.getDevUser(request);
if (authUser.user() == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,7 +41,6 @@

@Service
@Slf4j
@Transactional
@RequiredArgsConstructor
public class MentoringManageUseCase {
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<Mentoring> 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<Mentoring> expectedMentorings = mentoringGetService.byStatus(EXPECTED);
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,6 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -24,8 +24,11 @@ public class MentoringGetService {

private final MentoringRepository mentoringRepository;

public Optional<Mentoring> byPayment(Payment payment) {
return mentoringRepository.findByPayment(payment);
public void byPayment(Payment payment) {
mentoringRepository.findByPayment(payment)
.ifPresent(mentoring -> {
throw new MentoringPresentException();
});
}

public List<Mentoring> byUser(User user, Status status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 7bd0968

Please sign in to comment.