Skip to content

Commit

Permalink
Merge pull request #305 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ywj9811 authored Aug 6, 2024
2 parents 7bc7cae + 6271150 commit 6a774ec
Show file tree
Hide file tree
Showing 160 changed files with 1,131 additions and 956 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
import com.postgraduate.domain.salary.domain.entity.SalaryAccount;
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.user.user.application.utils.UserUtils;
import com.postgraduate.domain.user.user.domain.entity.User;
import com.postgraduate.domain.user.user.domain.entity.constant.Role;
import com.postgraduate.domain.wish.domain.entity.Wish;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import static com.postgraduate.domain.mentoring.domain.entity.constant.TermUnit.SHORT;

@RequiredArgsConstructor
@Component
@Slf4j
public class AdminMapper {
private AdminMapper() {
throw new IllegalStateException();
}
private final UserUtils userUtils;

public static CertificationDetailsResponse mapToCertificationInfo(Senior senior) {
public CertificationDetailsResponse mapToCertificationInfo(Senior senior) {
User user = senior.getUser();
Info info = senior.getInfo();
return new CertificationDetailsResponse(
Expand All @@ -36,7 +42,7 @@ public static CertificationDetailsResponse mapToCertificationInfo(Senior senior)
);
}

public static UserInfo mapToUserInfo(Wish wish) {
public UserInfo mapToUserInfo(Wish wish) {
User user = wish.getUser();
Boolean isSenior = user.getRole() == Role.SENIOR;
return new UserInfo(
Expand All @@ -52,7 +58,7 @@ public static UserInfo mapToUserInfo(Wish wish) {
);
}

public static SeniorInfo mapToSeniorInfo(Senior senior, int totalAmount, Boolean isUser) {
public SeniorInfo mapToSeniorInfo(Senior senior, int totalAmount, Boolean isUser) {
User user = senior.getUser();
return new SeniorInfo(
senior.getSeniorId(),
Expand All @@ -65,21 +71,24 @@ public static SeniorInfo mapToSeniorInfo(Senior senior, int totalAmount, Boolean
);
}

public static MentoringInfo mapToMentoringInfoWithSenior(Mentoring mentoring) {
public MentoringInfo mapToMentoringInfoWithUser(Mentoring mentoring) {
if (mentoring.getSenior() == null || mentoring.getSenior().getUser().isDelete()) {
return getMentoringInfo(mentoring, userUtils.getArchiveUser());
}
Senior senior = mentoring.getSenior();
return getMentoringInfo(mentoring, senior.getUser());
}

public MentoringInfo mapToMentoringInfoWithSenior(Mentoring mentoring) {
if (mentoring.getUser() == null || mentoring.getUser().isDelete()) {
return getMentoringInfo(mentoring, userUtils.getArchiveUser());
}
User user = mentoring.getUser();
return new MentoringInfo(
mentoring.getMentoringId(),
mentoring.getStatus(),
user.getNickName(),
user.getPhoneNumber(),
mentoring.getCreatedAt(),
mentoring.getDate()
);
return getMentoringInfo(mentoring, user);
}

public static MentoringInfo mapToMentoringInfoWithUser(Mentoring mentoring) {
Senior senior = mentoring.getSenior();
User user = senior.getUser();
@NotNull
private MentoringInfo getMentoringInfo(Mentoring mentoring, User user) {
return new MentoringInfo(
mentoring.getMentoringId(),
mentoring.getStatus(),
Expand All @@ -90,40 +99,35 @@ public static MentoringInfo mapToMentoringInfoWithUser(Mentoring mentoring) {
);
}

public static UserMentoringInfo mapToUserMentoringInfo(User user) {

public UserMentoringInfo mapToUserMentoringInfo(User user) {
return new UserMentoringInfo(
user.getNickName(),
user.getPhoneNumber()
);
}

public static UserMentoringInfo mapToUserMentoringInfo(Senior senior) {
public UserMentoringInfo mapToUserMentoringInfo(Senior senior) {
User user = senior.getUser();
return new UserMentoringInfo(
user.getNickName(),
user.getPhoneNumber()
);
}

public static PaymentInfo mapToPaymentInfo(Mentoring mentoring) {
Payment payment = mentoring.getPayment();
User user = mentoring.getUser();
return new PaymentInfo(
payment.getPaymentId(),
mentoring.getMentoringId(),
user.getNickName(),
user.getPhoneNumber(),
payment.getPaidAt(),
payment.getPay(),
payment.getStatus()
);
public PaymentInfo mapToPaymentInfo(Payment payment, Mentoring mentoring) {
if (payment.getUser() == null) {
return getPaymentInfo(payment, mentoring.getMentoringId(), userUtils.getArchiveUser());
}
User user = payment.getUser();
return getPaymentInfo(payment, mentoring.getMentoringId(), user);
}

public static PaymentInfo mapToPaymentInfo(Payment payment, Mentoring mentoring) {
User user = payment.getUser();
@NotNull
private PaymentInfo getPaymentInfo(Payment payment, Long mentoring, User user) {
return new PaymentInfo(
payment.getPaymentId(),
mentoring.getMentoringId(),
mentoring,
user.getNickName(),
user.getPhoneNumber(),
payment.getPaidAt(),
Expand All @@ -132,20 +136,12 @@ public static PaymentInfo mapToPaymentInfo(Payment payment, Mentoring mentoring)
);
}

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

public static SalaryInfoWithOutId mapToSalaryResponse(Senior senior, String accountNumber, Salary salary) {
public SalaryInfoWithOutId mapToSalaryResponse(Senior senior, String accountNumber, Salary salary) {
User user = senior.getUser();
SalaryAccount account = salary.getAccount();
return new SalaryInfoWithOutId(
Expand All @@ -159,7 +155,7 @@ public static SalaryInfoWithOutId mapToSalaryResponse(Senior senior, String acco
);
}

public static SalaryInfoWithOutId mapToSalaryResponse(Senior senior, Salary salary) {
public SalaryInfoWithOutId mapToSalaryResponse(Senior senior, Salary salary) {
User user = senior.getUser();
return new SalaryInfoWithOutId (
user.getNickName(),
Expand All @@ -169,7 +165,18 @@ public static SalaryInfoWithOutId mapToSalaryResponse(Senior senior, Salary sala
);
}

public static UnSettledSalaryInfo mapToUnSettledSalaryResponse(Salary salary) {
public SalaryInfoWithOutId mapToSalaryResponse(Salary salary) {
User user = userUtils.getArchiveUser();
return new SalaryInfoWithOutId (
user.getNickName(),
user.getPhoneNumber(),
salary.getTotalAmount(),
salary.getSalaryDoneDate()
);
}


public UnSettledSalaryInfo mapToUnSettledSalaryResponse(Salary salary) {
Senior senior = salary.getSenior();
User user = senior.getUser();
return new UnSettledSalaryInfo(
Expand All @@ -181,7 +188,7 @@ public static UnSettledSalaryInfo mapToUnSettledSalaryResponse(Salary salary) {
);
}

public static UnSettledSalaryInfo mapToUnSettledSalaryResponse(Salary salary, String accountNumber) {
public UnSettledSalaryInfo mapToUnSettledSalaryResponse(Salary salary, String accountNumber) {
Senior senior = salary.getSenior();
User user = senior.getUser();
SalaryAccount account = salary.getAccount();
Expand All @@ -197,25 +204,44 @@ public static UnSettledSalaryInfo mapToUnSettledSalaryResponse(Salary salary, St
);
}

public static MentoringWithPaymentResponse mapToMentoringWithPaymentResponse(Mentoring mentoring) {
User user = mentoring.getUser();
Senior senior = mentoring.getSenior();
public MentoringWithPaymentResponse mapToMentoringWithPaymentResponse(Mentoring mentoring) {
User user;
User senior;
if (mentoring.getUser() == null || mentoring.getUser().isDelete()) {
log.info("user is Null");
user = userUtils.getArchiveUser();
}
else {
user = mentoring.getUser();
}
if (mentoring.getSenior().getUser() == null || mentoring.getSenior().getUser().isDelete()) {
log.info("senior is Null");
senior = userUtils.getArchiveUser();
}
else {
senior = mentoring.getSenior().getUser();
}
Payment payment = mentoring.getPayment();
return getMentoringWithPaymentResponse(mentoring, user, senior, payment);
}

@NotNull
private static MentoringWithPaymentResponse getMentoringWithPaymentResponse(Mentoring mentoring, User user, User senior, Payment payment) {
return new MentoringWithPaymentResponse(
mentoring.getMentoringId(),
payment.getPaymentId(),
user.getNickName(),
user.getPhoneNumber(),
senior.getUser().getNickName(),
senior.getUser().getPhoneNumber(),
senior.getNickName(),
senior.getPhoneNumber(),
mentoring.getDate(),
mentoring.getTerm(),
payment.getPay(),
SHORT.getCharge()
);
}

public static WishResponse mapToWishResponse(Wish wish) {
public WishResponse mapToWishResponse(Wish wish) {
User user = wish.getUser();
return new WishResponse(
wish.getWishId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.postgraduate.admin.application.dto.req.Login;
import com.postgraduate.admin.domain.service.AuthGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
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 com.postgraduate.domain.user.user.domain.entity.User;
import com.postgraduate.domain.user.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.admin.application.mapper.AdminMapper.*;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE;

@Service
Expand All @@ -36,15 +35,16 @@ public class AdminMentoringUseCase {
private final PaymentManageUseCase paymentManageUseCase;
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;
private final AdminMapper adminMapper;

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

Expand All @@ -53,9 +53,9 @@ public MentoringManageResponse userMentoringInfos(Long userId) {
User user = userGetService.byUserId(userId);
List<Mentoring> mentorings = mentoringGetService.byUserId(userId);
List<MentoringInfo> mentoringInfos = mentorings.stream()
.map(AdminMapper::mapToMentoringInfoWithUser)
.map(adminMapper::mapToMentoringInfoWithUser)
.toList();
UserMentoringInfo userInfo = mapToUserMentoringInfo(user);
UserMentoringInfo userInfo = adminMapper.mapToUserMentoringInfo(user);
return new MentoringManageResponse(mentoringInfos, userInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.postgraduate.admin.application.dto.res.MentoringWithPaymentResponse;
import com.postgraduate.admin.application.dto.res.PaymentInfo;
import com.postgraduate.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;
Expand All @@ -12,16 +13,13 @@
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.user.domain.entity.User;
import com.postgraduate.domain.user.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.admin.application.mapper.AdminMapper.mapToMentoringWithPaymentResponse;
import static com.postgraduate.admin.application.mapper.AdminMapper.mapToPaymentInfo;

@Service
@Transactional
@RequiredArgsConstructor
Expand All @@ -32,6 +30,7 @@ public class AdminPaymentUseCase {
private final PaymentManageUseCase paymentManageUseCase;
private final SalaryGetService salaryGetService;
private final SalaryUpdateService salaryUpdateService;
private final AdminMapper adminMapper;

@Transactional(readOnly = true)
public List<PaymentInfo> paymentInfos() {
Expand All @@ -40,8 +39,8 @@ public List<PaymentInfo> paymentInfos() {
.map(payment -> {
Mentoring mentoring = mentoringGetService.byPaymentWithNull(payment);
if (mentoring == null)
return mapToPaymentInfo(payment);
return mapToPaymentInfo(payment, mentoring);
return adminMapper.mapToPaymentInfo(payment);
return adminMapper.mapToPaymentInfo(payment, mentoring);
})
.toList();
}
Expand All @@ -50,7 +49,7 @@ public List<PaymentInfo> paymentInfos() {
public MentoringWithPaymentResponse paymentMentoringInfo(Long paymentId) {
Payment payment = paymentGetService.byId(paymentId);
Mentoring mentoring = mentoringGetService.byPayment(payment);
return mapToMentoringWithPaymentResponse(mentoring);
return adminMapper.mapToMentoringWithPaymentResponse(mentoring);
}

public void refundPayment(User user, Long paymentId) {
Expand Down
Loading

0 comments on commit 6a774ec

Please sign in to comment.