Skip to content

Commit

Permalink
Merge pull request #178 from WE-ARE-RACCOONS/RAC-325
Browse files Browse the repository at this point in the history
RAC-325 fix: 결제 조회 오류 해결
  • Loading branch information
ywj9811 authored Mar 17, 2024
2 parents 8d0efcb + f7d0d14 commit 236d8ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ public static PaymentInfo mapToPaymentInfo(Payment payment, Mentoring mentoring)
);
}

public static PaymentInfo mapToPaymentInfo(Payment payment) {
User user = payment.getUser();
return new PaymentInfo(
payment.getPaymentId(),
null,
user.getNickName(),
user.getPhoneNumber(),
payment.getPaidAt(),
payment.getPay(),
payment.getStatus()
);
}

public static SalaryInfo mapToSalaryResponse(Senior senior, String accountNumber, Salary salary) {
User user = senior.getUser();
return new SalaryInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.postgraduate.domain.admin.application.dto.res.CertificationDetailsResponse;
import com.postgraduate.domain.admin.application.dto.res.MentoringManageResponse;
import com.postgraduate.domain.admin.application.dto.res.MentoringWithPaymentResponse;
import com.postgraduate.domain.admin.application.dto.res.WishResponse;
import com.postgraduate.domain.admin.application.mapper.AdminMapper;
import com.postgraduate.domain.admin.presentation.constant.SalaryStatus;
import com.postgraduate.domain.adminssr.application.dto.req.Login;
import com.postgraduate.domain.adminssr.domain.AuthGetService;
import com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService;
Expand All @@ -18,16 +18,13 @@
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.domain.salary.domain.service.SalaryUpdateService;
import com.postgraduate.domain.salary.exception.SalaryNotFoundException;
import com.postgraduate.domain.salary.exception.SalaryNotYetException;
import com.postgraduate.domain.salary.util.SalaryUtil;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.entity.constant.Status;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.senior.exception.SeniorCertificationException;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.admin.application.dto.res.WishResponse;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.domain.wish.domain.entity.Wish;
import com.postgraduate.domain.wish.domain.service.WishGetService;
Expand All @@ -40,6 +37,7 @@
import java.util.List;
import java.util.Optional;

import static com.postgraduate.domain.admin.application.mapper.AdminMapper.*;
import static com.postgraduate.domain.admin.presentation.constant.SalaryStatus.YET;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.CANCEL;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE;
Expand Down Expand Up @@ -74,7 +72,7 @@ public List<SeniorInfo> allSenior() {
Salary salary = salaryGetService.bySenior(senior);
SalaryStatus salaryStatus = getStatus(salary);
Optional<Wish> wish = wishGetService.byUser(senior.getUser());
return AdminMapper.mapToSeniorInfo(senior, salaryStatus, wish.isPresent());
return mapToSeniorInfo(senior, salaryStatus, wish.isPresent());
})
.toList();
}
Expand All @@ -91,9 +89,9 @@ public List<SalaryInfo> salaryInfos() {
return all.stream()
.map(salary -> {
if (salary.getAccountNumber() == null)
return AdminMapper.mapToSalaryResponse(salary.getSenior(), salary);
return mapToSalaryResponse(salary.getSenior(), salary);
String accountNumber = encryptorUtils.decryptData(salary.getAccountNumber());
return AdminMapper.mapToSalaryResponse(salary.getSenior(), accountNumber, salary);
return mapToSalaryResponse(salary.getSenior(), accountNumber, salary);
})
.toList();
}
Expand All @@ -102,8 +100,10 @@ public List<PaymentInfo> paymentInfos() {
List<Payment> all = paymentGetService.all();
return all.stream()
.map(payment -> {
Mentoring mentoring = mentoringGetService.byPayment(payment);
return AdminMapper.mapToPaymentInfo(payment, mentoring);
Mentoring mentoring = mentoringGetService.byPaymentWithNull(payment);
if (mentoring == null)
return mapToPaymentInfo(payment);
return mapToPaymentInfo(payment, mentoring);
})
.toList();
}
Expand All @@ -112,7 +112,7 @@ public CertificationDetailsResponse getCertification(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
if (senior.getStatus() == Status.APPROVE)
throw new SeniorCertificationException();
return AdminMapper.mapToCertificationInfo(senior);
return mapToCertificationInfo(senior);
}

public void updateNotApprove(Long seniorId) {
Expand All @@ -131,7 +131,7 @@ public MentoringManageResponse seniorMentorings(Long seniorId) {
List<MentoringInfo> mentoringInfos = mentorings.stream()
.map(AdminMapper::mapToMentoringInfo)
.toList();
UserMentoringInfo seniorInfo = AdminMapper.mapToUserMentoringInfo(senior);
UserMentoringInfo seniorInfo = mapToUserMentoringInfo(senior);
return new MentoringManageResponse(mentoringInfos, seniorInfo);
}

Expand All @@ -142,14 +142,14 @@ public SalaryInfo seniorSalary(Long seniorId) {
if (status != YET)
throw new SalaryNotYetException();
if (salary.getAccountNumber() == null)
return AdminMapper.mapToSalaryResponse(senior, salary);
return mapToSalaryResponse(senior, salary);
String accountNumber = encryptorUtils.decryptData(salary.getAccountNumber());
return AdminMapper.mapToSalaryResponse(senior, accountNumber, salary);
return mapToSalaryResponse(senior, accountNumber, salary);
}

public WishResponse wishInfo(Long userId) {
Wish wish = wishGetService.byUserId(userId);
return AdminMapper.mapToWishResponse(wish);
return mapToWishResponse(wish);
}

public MentoringManageResponse userMentoringInfos(Long userId) {
Expand All @@ -158,14 +158,14 @@ public MentoringManageResponse userMentoringInfos(Long userId) {
List<MentoringInfo> mentoringInfos = mentorings.stream()
.map(AdminMapper::mapToMentoringInfo)
.toList();
UserMentoringInfo userInfo = AdminMapper.mapToUserMentoringInfo(user);
UserMentoringInfo userInfo = mapToUserMentoringInfo(user);
return new MentoringManageResponse(mentoringInfos, userInfo);
}

public MentoringWithPaymentResponse paymentMentoringInfo(Long paymentId) {
Payment payment = paymentGetService.byId(paymentId);
Mentoring mentoring = mentoringGetService.byPayment(payment);
return AdminMapper.mapToMentoringWithPaymentResponse(mentoring);
return mapToMentoringWithPaymentResponse(mentoring);
}

public void wishDone(Long wishId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public void checkByPayment(Payment payment) {
});
}

public Mentoring byPaymentWithNull(Payment payment) {
return mentoringRepository.findByPayment(payment)
.orElse(null);
}

public Mentoring byPayment(Payment payment) {
return mentoringRepository.findByPayment(payment)
.orElseThrow(MentoringNotFoundException::new);
Expand Down

0 comments on commit 236d8ed

Please sign in to comment.