Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAC-257 feat : 결제 기능 추가 및 리팩토링" #89

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public record SalaryInfo(
String bank,
String accountNumber,
LocalDateTime salaryDoneDate
) {}
) {
public SalaryInfo(String nickName, String phoneNumber, int totalAmount, LocalDateTime salaryDoneDate) {
this(nickName, phoneNumber, totalAmount, null, null, null, salaryDoneDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ public record UserMentoringInfo(
String nickName,
String phoneNumber
) {
public UserMentoringInfo(String phoneNumber) {
this(null, phoneNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public record SalaryDetailsResponse(
String accountHolder,
String bank,
String accountNumber,
SalaryStatus status
Boolean status
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import com.postgraduate.domain.admin.presentation.constant.SalaryStatus;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.wish.application.dto.res.WishResponse;
import com.postgraduate.domain.wish.domain.entity.Wish;

import java.time.LocalDateTime;

public class AdminMapper {

public static CertificationDetailsResponse mapToCertificationInfo(Senior senior) {
Expand Down Expand Up @@ -89,7 +88,6 @@ public static MentoringInfo mapToSeniorMentoringInfo(Mentoring mentoring) {

public static UserMentoringInfo mapToUserMentoringInfo(User user) {
return new UserMentoringInfo(
null,
user.getPhoneNumber()
);
}
Expand All @@ -110,39 +108,36 @@ public static PaymentInfo mapToPaymentInfo(Payment payment) {
mentoring.getMentoringId(),
user.getNickName(),
user.getPhoneNumber(),
payment.getCreatedAt(),
mentoring.getPay(),
payment.getPaidAt(),
payment.getPay(),
payment.getStatus()
);
}

public static SalaryInfo mapToSalaryResponse(Senior senior, Account account, String accountNumber, int totalAmount, LocalDateTime salaryDoneDate) {
public static SalaryInfo mapToSalaryResponse(Senior senior, String accountNumber, Salary salary) {
User user = senior.getUser();
return new SalaryInfo(
user.getNickName(),
user.getPhoneNumber(),
totalAmount,
account.getAccountHolder(),
account.getBank(),
salary.getTotalAmount(),
salary.getAccountHolder(),
salary.getBank(),
accountNumber,
salaryDoneDate
salary.getSalaryDoneDate()
);
}

public static SalaryInfo mapToSalaryResponse(Senior senior, int totalAmount, LocalDateTime salaryDoneDate) {
public static SalaryInfo mapToSalaryResponse(Senior senior, Salary salary) {
User user = senior.getUser();
return new SalaryInfo(
user.getNickName(),
user.getPhoneNumber(),
totalAmount,
null,
null,
null,
salaryDoneDate
salary.getTotalAmount(),
salary.getSalaryDoneDate()
);
}

public static SalaryDetailsResponse mapToSalaryDetailsResponse(Senior senior, Account account, String accountNumber, int totalAmount, SalaryStatus status) {
public static SalaryDetailsResponse mapToSalaryDetailsResponse(Senior senior, Account account, String accountNumber, int totalAmount, Boolean status) {
User user = senior.getUser();
return new SalaryDetailsResponse(
user.getNickName(),
Expand All @@ -155,7 +150,7 @@ public static SalaryDetailsResponse mapToSalaryDetailsResponse(Senior senior, Ac
);
}

public static SalaryDetailsResponse mapToSalaryDetailsResponse(Senior senior, int totalAmount, SalaryStatus status) {
public static SalaryDetailsResponse mapToSalaryDetailsResponse(Senior senior, int totalAmount, Boolean status) {
User user = senior.getUser();
return new SalaryDetailsResponse(
user.getNickName(),
Expand All @@ -179,8 +174,8 @@ public static MentoringWithPaymentResponse mapToMentoringWithPaymentResponse(Pay
senior.getUser().getPhoneNumber(),
mentoring.getDate(),
mentoring.getTerm(),
(int) (mentoring.getPay() * 1.2),
(int) (mentoring.getPay() * 0.2)
payment.getPay(),
4000 //todo : 수수료 변경
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,42 @@ public class SalaryManageByAdminUseCase {

public SalaryDetailsResponse getSalary(Long seniorId) {
Senior senior = seniorGetService.bySeniorId(seniorId);
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDate(senior, getSalaryDate());
int totalAmount = getAmount(salaries);
SalaryStatus status = getStatus(salaries);
Salary salary = salaryGetService.bySenior(senior);

Optional<Account> optionalAccount = accountGetService.bySenior(senior);
if (optionalAccount.isPresent()) {
Account account = optionalAccount.get();
String accountNumber = encryptorUtils.decryptData(account.getAccountNumber());
return AdminMapper.mapToSalaryDetailsResponse(senior, account, accountNumber, totalAmount, status);
return AdminMapper.mapToSalaryDetailsResponse(senior, account, accountNumber, salary.getTotalAmount(), salary.getStatus());
}
return AdminMapper.mapToSalaryDetailsResponse(senior, totalAmount, status);
return AdminMapper.mapToSalaryDetailsResponse(senior, salary.getTotalAmount(), salary.getStatus());
}

public SalaryManageResponse getSalaries(Integer page, String search) {
Page<SeniorSalary> seniors = salaryGetService.findDistinctSeniors(search, page);
List<SalaryInfo> responses = new ArrayList<>();
seniors.forEach(senior -> {
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDateAndStatus(senior.senior(), senior.salaryDate(), true);
SalaryInfo response = getSalaryInfo(senior.senior(), salaries);
responses.add(response);
});
List<SalaryInfo> salaryInfos = seniors.stream()
.map(senior -> {
Salary salary = salaryGetService.bySenior(senior.senior());
return getSalaryInfo(senior.senior(), salary);
})
.toList();
Comment on lines +54 to +59
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public Salary bySenior(Senior senior) {
    LocalDate salaryDate = SalaryUtil.getSalaryDate();
    return salaryRepository.findBySeniorAndSalaryDate(senior, salaryDate).orElseThrow(SalaryNotFoundException::new);
}

정산정보를 현재의 salaryDate 를 기준으로 가져오던데, 이러면 과거의 정산 정보는 못 보지 않나요?
그리고 완료된 항목만 노출해야 할 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    @GetMapping("/salary")
    @Operation(summary = "[관리자] 정산 목록 조회", description = "한 달 기준으로 정산 목록을 조회합니다. 기준일은 [11일 ~ 내월 10일]입니다.")
    public ResponseDto<SalaryManageResponse> getSalaries(@RequestParam(required = false) Integer page,
                                                         @RequestParam(required = false) String search) {
        SalaryManageResponse salaries = salaryManageUseCase.getSalaries(page, search);
        return ResponseDto.create(ADMIN_FIND.getCode(), GET_LIST.getMessage(), salaries);
    }

컨트롤러에 이렇게 나와있어서 맞춰서 했었는데 저도 이 부분에 대해서는 논의를 해보려고 했어요!
일단 이 부분은 방식에 대해서 추가로 논의하는게 어떨까요? 관리자 부분은 후순위이다 보니

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 제가 이후에 로직을 수정하고 설명은 수정을 안 했네요 ㅜㅜ

Long totalElements = seniors.getTotalElements();
int totalPages = seniors.getTotalPages();
return new SalaryManageResponse(responses, totalElements, totalPages);
return new SalaryManageResponse(salaryInfos, totalElements, totalPages);
}

private SalaryInfo getSalaryInfo(Senior senior, List<Salary> salaries) {
int totalAmount = getAmount(salaries);
LocalDateTime salaryDoneDate = getDoneDate(salaries);

private SalaryInfo getSalaryInfo(Senior senior, Salary salary) {
Optional<Account> optionalAccount = accountGetService.bySenior(senior);
if (optionalAccount.isPresent()) {
Account account = optionalAccount.get();
String accountNumber = encryptorUtils.decryptData(account.getAccountNumber());
return AdminMapper.mapToSalaryResponse(senior, account, accountNumber, totalAmount, salaryDoneDate);
String accountNumber = encryptorUtils.decryptData(salary.getAccountNumber());
return AdminMapper.mapToSalaryResponse(senior, accountNumber, salary);
}
return AdminMapper.mapToSalaryResponse(senior, totalAmount, salaryDoneDate);
return AdminMapper.mapToSalaryResponse(senior, salary);
}

public void updateSalaryStatus(Long seniorId, Boolean status) {
Senior senior = seniorGetService.bySeniorId(seniorId);
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDate(senior, getSalaryDate());
salaries.forEach(salary -> salaryUpdateService.updateStatus(salary, status));
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.updateStatus(salary, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public SeniorManageResponse getSeniors(Integer page, String search) {
Page<Senior> seniors = seniorGetService.all(page, search);
List<SeniorInfo> seniorInfos = seniors.stream()
.map(senior -> {
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDate(senior, getSalaryDate());
SalaryStatus salaryStatus = getStatus(salaries);
Salary salary = salaryGetService.bySenior(senior);
SalaryStatus salaryStatus = getStatus(salary);
Optional<Wish> wish = wishGetService.byUser(senior.getUser());
return AdminMapper.mapToSeniorInfo(senior, salaryStatus, wish.isPresent());
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum SalaryStatus {
DONE, YET, NONE
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.postgraduate.domain.auth.application.dto.req;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;

public record SeniorSignUpRequest(@NotEmpty Long socialId, @NotBlank String phoneNumber, @NotBlank String nickName,
@NotBlank Boolean marketingReceive, @NotBlank String major, @NotBlank String postgradu,
public record SeniorSignUpRequest(Long socialId, @NotBlank String phoneNumber, @NotBlank String nickName,
Boolean marketingReceive, @NotBlank String major, @NotBlank String postgradu,
@NotBlank String professor, @NotBlank String lab, @NotBlank String field,
@NotBlank String keyword, @NotBlank String certification) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.auth.application.dto.req.SignUpRequest;
import com.postgraduate.domain.auth.application.dto.req.UserChangeRequest;
import com.postgraduate.domain.salary.application.mapper.SalaryMapper;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.salary.domain.service.SalarySaveService;
import com.postgraduate.domain.salary.util.SalaryUtil;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.application.utils.SeniorUtils;
import com.postgraduate.domain.senior.domain.entity.Senior;
Expand All @@ -22,10 +26,13 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate;

@Transactional
@Service
@RequiredArgsConstructor
public class SignUpUseCase {
private final SalarySaveService salarySaveService;
private final UserSaveService userSaveService;
private final UserUpdateService userUpdateService;
private final UserGetService userGetService;
Expand All @@ -50,6 +57,8 @@ public User seniorSignUp(SeniorSignUpRequest request) {
userSaveService.saveUser(user);
Senior senior = SeniorMapper.mapToSenior(user, request);
seniorSaveService.saveSenior(senior);
Salary salary = SalaryMapper.mapToSalary(senior, getSalaryDate());
salarySaveService.saveSalary(salary);
return senior.getUser();
}

Expand All @@ -59,6 +68,8 @@ public User changeSenior(User user, SeniorChangeRequest changeRequest) {
seniorSaveService.saveSenior(senior);
user = userGetService.getUser(user.getUserId());
userUpdateService.updateRole(user, Role.SENIOR);
Salary salary = SalaryMapper.mapToSalary(senior, getSalaryDate());
salarySaveService.saveSalary(salary);
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Profile;
Expand Down Expand Up @@ -102,7 +103,8 @@ public static ExpectedSeniorMentoringInfo mapToSeniorExpectedInfo(Mentoring ment
mentoring.getDate());
}

public static DoneSeniorMentoringInfo mapToSeniorDoneInfo(Mentoring mentoring, Salary salary) {
public static DoneSeniorMentoringInfo mapToSeniorDoneInfo(Mentoring mentoring, Payment payment) {
Salary salary = payment.getSalary();
User user = mentoring.getUser();
return new DoneSeniorMentoringInfo(mentoring.getMentoringId(),
user.getProfile(), user.getNickName(),
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멘토링을 취소 또는 거절하는 경우에 payment 변경 로직이 필요할 것 같습니닷..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분은 환불 로직을 추가하면서 하려고 합니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다!

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import com.postgraduate.domain.refuse.application.mapper.RefuseMapper;
import com.postgraduate.domain.refuse.domain.entity.Refuse;
import com.postgraduate.domain.refuse.domain.service.RefuseSaveService;
import com.postgraduate.domain.salary.application.mapper.SalaryMapper;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.salary.domain.service.SalarySaveService;
import com.postgraduate.domain.salary.util.SalaryUtil;
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;
Expand All @@ -24,7 +23,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
Expand All @@ -39,9 +37,10 @@ public class MentoringManageUseCase {
private final MentoringUpdateService mentoringUpdateService;
private final MentoringGetService mentoringGetService;
private final RefuseSaveService refuseSaveService;
private final SalarySaveService salarySaveService;
private final AccountGetService accountGetService;
private final SeniorGetService seniorGetService;
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;

public void updateCancel(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId);
Expand All @@ -54,16 +53,11 @@ public void updateDone(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId);
if (mentoring.getStatus() != EXPECTED)
throw new MentoringNotExpectedException();
createSalary(mentoring);
Salary salary = salaryGetService.bySenior(mentoring.getSenior());
salaryUpdateService.updateTotalAmount(salary);
mentoringUpdateService.updateStatus(mentoring, DONE);
}

private void createSalary(Mentoring mentoring) {
LocalDate salaryDate = SalaryUtil.getSalaryDate();
Salary salary = SalaryMapper.mapToSalary(mentoring, salaryDate);
salarySaveService.saveSalary(salary);
}

public void updateRefuse(User user, Long mentoringId, MentoringRefuseRequest request) {
Senior senior = seniorGetService.byUser(user);
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(senior, mentoringId);
Expand Down Expand Up @@ -105,8 +99,10 @@ public void updateAutoDone() {
expectedMentorings.stream()
.filter(Mentoring::checkAutoDone)
.forEach(mentoring -> {
createSalary(mentoring);
mentoringUpdateService.updateStatus(mentoring, DONE);
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.updateTotalAmount(salary);
//TODO : 알림 보내거나 나머지 작업
});
}
Expand Down
Loading
Loading