Skip to content

Commit

Permalink
Merge pull request #181 from WE-ARE-RACCOONS/RAC-325
Browse files Browse the repository at this point in the history
RAC-325 feat : 환불 기능 추가
  • Loading branch information
ywj9811 authored Mar 18, 2024
2 parents 236d8ed + 69fecd2 commit 36052df
Show file tree
Hide file tree
Showing 39 changed files with 482 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public MentoringWithPaymentResponse getMentoringWithPayment(Long mentoringId) {

public void cancelMentoring(Long mentoringId) {
Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId);
mentoringUpdateService.updateStatus(mentoring, Status.CANCEL);
mentoringUpdateService.updateCancel(mentoring);
Payment payment = mentoring.getPayment();
User user = mentoring.getUser();
paymentManageUseCase.refundPayByUser(user, payment.getOrderId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;
import java.util.Optional;

import static java.lang.Boolean.TRUE;

@Service
@Transactional
@RequiredArgsConstructor
Expand Down Expand Up @@ -69,6 +71,10 @@ private SalaryInfo getSalaryInfo(Senior senior, Salary salary) {
public void updateSalaryStatus(Long seniorId, Boolean status) {
Senior senior = seniorGetService.bySeniorId(seniorId);
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.updateStatus(salary, status);
if (TRUE.equals(status)) {
salaryUpdateService.updateDone(salary);
return;
}
salaryUpdateService.updateNot(salary);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Optional;

import static com.postgraduate.domain.salary.util.SalaryUtil.getStatus;
import static com.postgraduate.domain.senior.domain.entity.constant.Status.APPROVE;

@Service
@Transactional
Expand All @@ -44,7 +45,11 @@ public CertificationDetailsResponse getCertificationDetails(Long seniorId) {

public void updateSeniorStatus(Long seniorId, SeniorStatusRequest request) {
Senior senior = seniorGetService.bySeniorId(seniorId);
seniorUpdateService.updateCertificationStatus(senior, request.certificationStatus());
if (request.certificationStatus() == APPROVE) {
seniorUpdateService.certificationUpdateApprove(senior);
return;
}
seniorUpdateService.certificationUpdateNotApprove(senior);
}

public SeniorManageResponse getSeniors(Integer page, String search) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void updateWishStatus(Long wishId) {
if (wish.getMajor() == null && wish.getField() == null) {
throw new WishEmptyException();
}
wishUpdateService.updateWishStatus(wish);
wishUpdateService.updateWishDone(wish);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.postgraduate.domain.adminssr.application.usecase;

import com.postgraduate.domain.adminssr.application.dto.req.Login;
import com.postgraduate.domain.adminssr.domain.service.AuthGetService;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminAuthUseCase {
private final AuthGetService authGetService;

public User login(Login loginForm) {
return authGetService.login(loginForm.nickName(), loginForm.phoneNumber());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.postgraduate.domain.adminssr.application.usecase;

import com.postgraduate.domain.admin.application.dto.MentoringInfo;
import com.postgraduate.domain.admin.application.dto.UserMentoringInfo;
import com.postgraduate.domain.admin.application.dto.res.MentoringManageResponse;
import com.postgraduate.domain.admin.application.dto.res.MentoringWithPaymentResponse;
import com.postgraduate.domain.admin.application.mapper.AdminMapper;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService;
import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.payment.domain.service.PaymentGetService;
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.senior.domain.entity.Senior;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.postgraduate.domain.admin.application.mapper.AdminMapper.mapToMentoringWithPaymentResponse;
import static com.postgraduate.domain.admin.application.mapper.AdminMapper.mapToUserMentoringInfo;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminMentoringUseCase {
private final MentoringGetService mentoringGetService;
private final MentoringUpdateService mentoringUpdateService;
private final SeniorGetService seniorGetService;
private final UserGetService userGetService;
private final PaymentGetService paymentGetService;
private final PaymentManageUseCase paymentManageUseCase;
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;

public MentoringManageResponse seniorMentorings(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
List<Mentoring> mentorings = mentoringGetService.bySeniorId(seniorId);
List<MentoringInfo> mentoringInfos = mentorings.stream()
.map(AdminMapper::mapToMentoringInfo)
.toList();
UserMentoringInfo seniorInfo = mapToUserMentoringInfo(senior);
return new MentoringManageResponse(mentoringInfos, seniorInfo);
}

public MentoringManageResponse userMentoringInfos(Long userId) {
User user = userGetService.byUserId(userId);
List<Mentoring> mentorings = mentoringGetService.byUserId(userId);
List<MentoringInfo> mentoringInfos = mentorings.stream()
.map(AdminMapper::mapToMentoringInfo)
.toList();
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 mapToMentoringWithPaymentResponse(mentoring);
}

public void refundMentoring(User user, Long mentoringId) {
Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId);
Payment payment = mentoring.getPayment();
paymentManageUseCase.refundPayByAdmin(user, payment.getPaymentId());
if (mentoring.getStatus() == DONE) {
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.minusTotalAmount(salary);
}
mentoringUpdateService.updateCancel(mentoring);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.postgraduate.domain.adminssr.application.usecase;

import com.postgraduate.domain.admin.application.dto.PaymentInfo;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.payment.domain.service.PaymentGetService;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.postgraduate.domain.admin.application.mapper.AdminMapper.mapToPaymentInfo;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminPaymentUseCase {
private final PaymentGetService paymentGetService;
private final MentoringGetService mentoringGetService;
private final PaymentManageUseCase paymentManageUseCase;

public List<PaymentInfo> paymentInfos() {
List<Payment> all = paymentGetService.all();
return all.stream()
.map(payment -> {
Mentoring mentoring = mentoringGetService.byPaymentWithNull(payment);
if (mentoring == null)
return mapToPaymentInfo(payment);
return mapToPaymentInfo(payment, mentoring);
})
.toList();
}

public void refundPayment(User user, Long paymentId) {
paymentManageUseCase.refundPayByAdmin(user, paymentId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.postgraduate.domain.adminssr.application.usecase;

import com.postgraduate.domain.admin.application.dto.SalaryInfo;
import com.postgraduate.domain.admin.presentation.constant.SalaryStatus;
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.SalaryNotYetException;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.global.config.security.util.EncryptorUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.postgraduate.domain.admin.application.mapper.AdminMapper.mapToSalaryResponse;
import static com.postgraduate.domain.admin.presentation.constant.SalaryStatus.DONE;
import static com.postgraduate.domain.admin.presentation.constant.SalaryStatus.YET;
import static com.postgraduate.domain.salary.util.SalaryUtil.getStatus;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminSalaryUseCase {
private final SeniorGetService seniorGetService;
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;
private final EncryptorUtils encryptorUtils;

public List<SalaryInfo> salaryInfos() {
List<Salary> all = salaryGetService.findAll();
return all.stream()
.filter(salary -> getStatus(salary) == DONE)
.map(salary -> {
if (salary.getAccountNumber() == null)
return mapToSalaryResponse(salary.getSenior(), salary);
String accountNumber = encryptorUtils.decryptData(salary.getAccountNumber());
return mapToSalaryResponse(salary.getSenior(), accountNumber, salary);
})
.toList();
}

public SalaryInfo seniorSalary(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
Salary salary = salaryGetService.bySeniorLastWeek(senior);
SalaryStatus status = getStatus(salary);
if (status != YET)
throw new SalaryNotYetException();
if (salary.getAccountNumber() == null)
return mapToSalaryResponse(senior, salary);
String accountNumber = encryptorUtils.decryptData(salary.getAccountNumber());
return mapToSalaryResponse(senior, accountNumber, salary);
}

public void salaryDone(Long salaryId) {
Salary salary = salaryGetService.bySalaryId(salaryId);
salaryUpdateService.updateDone(salary);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.postgraduate.domain.adminssr.application.usecase;

import com.postgraduate.domain.admin.application.dto.SeniorInfo;
import com.postgraduate.domain.admin.application.dto.res.CertificationDetailsResponse;
import com.postgraduate.domain.admin.presentation.constant.SalaryStatus;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.domain.senior.domain.entity.Senior;
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.wish.domain.entity.Wish;
import com.postgraduate.domain.wish.domain.service.WishGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

import static com.postgraduate.domain.admin.application.mapper.AdminMapper.mapToCertificationInfo;
import static com.postgraduate.domain.admin.application.mapper.AdminMapper.mapToSeniorInfo;
import static com.postgraduate.domain.salary.util.SalaryUtil.getStatus;
import static com.postgraduate.domain.senior.domain.entity.constant.Status.APPROVE;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminSeniorUseCase {
private final SeniorGetService seniorGetService;
private final SeniorUpdateService seniorUpdateService;
private final SalaryGetService salaryGetService;
private final WishGetService wishGetService;

public List<SeniorInfo> allSenior() {
List<Senior> seniors = seniorGetService.allSeniorId();
return seniors.stream()
.map(senior -> {
Salary salary = salaryGetService.bySeniorLastWeek(senior);
SalaryStatus salaryStatus = getStatus(salary);
Optional<Wish> wish = wishGetService.byUser(senior.getUser());
return mapToSeniorInfo(senior, salaryStatus, wish.isPresent());
})
.toList();
}

public CertificationDetailsResponse getCertification(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
if (senior.getStatus() == APPROVE)
throw new SeniorCertificationException();
return mapToCertificationInfo(senior);
}


public void updateNotApprove(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
seniorUpdateService.certificationUpdateNotApprove(senior);
}

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

}
Loading

0 comments on commit 36052df

Please sign in to comment.