Skip to content

Commit

Permalink
Merge pull request #168 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 11, 2024
2 parents 36778cb + 96e7317 commit 35c8c0b
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public static ExpectedSeniorMentoringInfo mapToSeniorExpectedInfo(Mentoring ment
dDay);
}

public static DoneSeniorMentoringInfo mapToSeniorDoneInfo(Mentoring mentoring, Payment payment) {
Salary salary = payment.getSalary();
public static DoneSeniorMentoringInfo mapToSeniorDoneInfo(Mentoring mentoring) {
Salary salary = mentoring.getSalary();
User user = mentoring.getUser();
return new DoneSeniorMentoringInfo(mentoring.getMentoringId(),
user.getProfile(), user.getNickName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.payment.exception.PaymentNotFoundException;
import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest;
import com.postgraduate.domain.refuse.application.mapper.RefuseMapper;
import com.postgraduate.domain.refuse.domain.entity.Refuse;
Expand Down Expand Up @@ -60,16 +61,20 @@ public class MentoringManageUseCase {

@Transactional
public boolean applyMentoringWithPayment(User user, MentoringApplyRequest request) {
Payment payment = paymentGetService.byUserAndOrderId(user, request.orderId());
mentoringGetService.byPayment(payment);
Payment payment = null;
try {
payment = paymentGetService.byUserAndOrderId(user, request.orderId());
mentoringGetService.byPayment(payment);
String[] dates = request.date().split(",");
if (dates.length != 3)
throw new MentoringDateException();
Senior senior = payment.getSalary().getSenior();
Senior senior = payment.getSenior();
Mentoring mentoring = MentoringMapper.mapToMentoring(user, senior, payment, request);
mentoringSaveService.save(mentoring);
return true;
} catch (PaymentNotFoundException ex) {
log.error("κ²°μ œκ±΄μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.");
return false;
} catch (Exception ex) {
paymentManageUseCase.refundPayByUser(user, payment.getOrderId());
return false;
Expand All @@ -94,7 +99,7 @@ public void updateDone(User user, Long mentoringId) {
throw new MentoringNotExpectedException();
Salary salary = salaryGetService.bySenior(mentoring.getSenior());
salaryUpdateService.updateTotalAmount(salary);
mentoringUpdateService.updateStatus(mentoring, DONE);
mentoringUpdateService.updateDone(mentoring, salary);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public void updateCancelWithAuto(Mentoring mentoring) {
public void updateDoneWithAuto(Mentoring mentoring) {
try {
Mentoring doneMentoring = mentoringGetService.byMentoringIdWithLazy(mentoring.getMentoringId());
mentoringUpdateService.updateStatus(doneMentoring, DONE);
Senior senior = mentoring.getSenior();
Salary salary = salaryGetService.bySenior(senior);
salaryUpdateService.updateTotalAmount(salary);
mentoringUpdateService.updateDone(doneMentoring, salary);
log.info("mentoringId : {} μžλ™ μ™„λ£Œ", mentoring.getMentoringId());
} catch (Exception ex) {
slackErrorMessage.sendSlackError(mentoring, ex);
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.WaitingSeniorMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringResponse;
import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
Expand Down Expand Up @@ -74,7 +75,7 @@ public SeniorMentoringResponse getSeniorExpected(User user) {
public SeniorMentoringResponse getSeniorDone(User user) {
List<Mentoring> mentorings = getDoneMentorings(user);
List<DoneSeniorMentoringInfo> doneSeniorMentoringInfos = mentorings.stream()
.map(mentoirng -> mapToSeniorDoneInfo(mentoirng, mentoirng.getPayment()))
.map(MentoringMapper::mapToSeniorDoneInfo)
.toList();
return new SeniorMentoringResponse(doneSeniorMentoringInfos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import jakarta.persistence.*;
Expand All @@ -15,6 +16,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE;
import static java.time.LocalDateTime.now;
import static java.time.LocalDateTime.parse;
import static java.time.format.DateTimeFormatter.ofPattern;
Expand All @@ -38,6 +40,9 @@ public class Mentoring {
@OneToOne(fetch = FetchType.LAZY)
private Payment payment;

@ManyToOne(fetch = FetchType.LAZY)
private Salary salary;

@Column(nullable = false, columnDefinition = "TEXT")
private String topic;

Expand Down Expand Up @@ -65,6 +70,11 @@ public void updateStatus(Status status) {
this.status = status;
}

public void updateDone(Salary salary) {
this.status = DONE;
this.salary = salary;
}

public void updateDate(String date) {
this.date = date;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static com.postgraduate.domain.mentoring.domain.entity.QMentoring.mentoring;
import static com.postgraduate.domain.payment.domain.entity.QPayment.payment;
import static com.postgraduate.domain.payment.domain.entity.constant.Status.DONE;
import static com.postgraduate.domain.salary.domain.entity.QSalary.salary;
import static com.postgraduate.domain.senior.domain.entity.QSenior.senior;
import static com.postgraduate.domain.user.domain.entity.QUser.user;
Expand Down Expand Up @@ -111,16 +110,13 @@ public List<Mentoring> findAllBySeniorAndSalaryStatus(Senior senior, Boolean sta
.where(
mentoring.senior.eq(senior),
mentoring.status.eq(Status.DONE),
mentoring.payment.status.eq(DONE),
mentoring.payment.salary.status.eq(status)
mentoring.salary.status.eq(status)
)
.join(mentoring.payment, payment)
.fetchJoin()
.join(mentoring.payment.salary, salary)
.join(mentoring.salary, salary)
.fetchJoin()
.join(mentoring.user, user)
.fetchJoin()
.orderBy(mentoring.payment.salary.salaryDate.desc(), mentoring.updatedAt.desc())
.orderBy(mentoring.salary.salaryDate.desc(), mentoring.updatedAt.desc())
.fetch();
}

Expand Down Expand Up @@ -179,7 +175,7 @@ public List<Mentoring> findAllByStatus(Status status) {
.distinct()
.join(mentoring.senior, senior)
.fetchJoin()
.join(mentoring.payment.salary, salary)
.join(mentoring.salary, salary)
.fetchJoin()
.where(mentoring.status.eq(status))
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.salary.domain.entity.Salary;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -13,6 +14,10 @@ public void updateStatus(Mentoring mentoring, Status status) {
mentoring.updateStatus(status);
}

public void updateDone(Mentoring mentoring, Salary salary) {
mentoring.updateDone(salary);
}

public void updateDate(Mentoring mentoring, String date) {
mentoring.updateDate(date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.postgraduate.domain.payment.application.dto.req.PaymentResultRequest;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;

import java.time.LocalDateTime;
Expand All @@ -13,11 +13,11 @@ private PaymentMapper() {
throw new IllegalArgumentException();
}

public static Payment resultToPayment(Salary salary, User user, PaymentResultRequest request) {
public static Payment resultToPayment(Senior senior, User user, PaymentResultRequest request) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
return Payment.builder()
.salary(salary)
.user(user)
.senior(senior)
.pay(Integer.parseInt(request.PCD_PAY_TOTAL()))
.orderId(request.PCD_PAY_OID())
.cardAuthNumber(request.PCD_PAY_CARDAUTHNO())
Expand All @@ -29,8 +29,6 @@ public static Payment resultToPayment(Salary salary, User user, PaymentResultReq
public static Payment resultToPayment(PaymentResultRequest request) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
return Payment.builder()
.salary(null)
.user(null)
.pay(Integer.parseInt(request.PCD_PAY_TOTAL()))
.orderId(request.PCD_PAY_OID())
.cardAuthNumber(request.PCD_PAY_CARDAUTHNO())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import com.postgraduate.domain.payment.domain.service.PaymentSaveService;
import com.postgraduate.domain.payment.domain.service.PaymentUpdateService;
import com.postgraduate.domain.payment.exception.CertificationFailException;
import com.postgraduate.domain.payment.exception.PaymentFailException;
import com.postgraduate.domain.payment.exception.RefundFailException;
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.user.domain.entity.User;
Expand All @@ -31,7 +28,6 @@
import java.util.Optional;

import static com.postgraduate.domain.payment.application.usecase.PaymentParameter.*;
import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseCode.PAYMENT_FAIL;
import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseMessage.FAIL_PAYMENT;
import static org.springframework.http.CacheControl.noCache;

Expand Down Expand Up @@ -60,30 +56,27 @@ public class PaymentManageUseCase {
private final PaymentUpdateService paymentUpdateService;
private final SeniorGetService seniorGetService;
private final UserGetService userGetService;
private final SalaryGetService salaryGetService;
private final WebClient webClient;

public boolean savePay(PaymentResultRequest request) {
public void savePay(PaymentResultRequest request) {
if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) {
log.error("PayPle 결제 진행 μ·¨μ†Œ 및 였λ₯˜");
log.error("message : {} code : {}", FAIL_PAYMENT.getMessage(), request.PCD_PAY_CODE());
return false;
return;
}
try {
String seniorNickName = request.PCD_PAY_GOODS();
long userId = Long.parseLong(request.PCD_PAYER_NO());
User user = userGetService.byUserId(userId);
Senior senior = seniorGetService.bySeniorNickName(seniorNickName);
Salary salary = salaryGetService.bySenior(senior);
Payment payment = PaymentMapper.resultToPayment(salary, user, request);
Payment payment = PaymentMapper.resultToPayment(senior, user, request);
paymentSaveService.save(payment);
} catch (Exception ex) {
log.error("paymentError λ°œμƒ ν™˜λΆˆ 진행 | errorMessage : {}", ex.getMessage());
Payment payment = PaymentMapper.resultToPayment(request);
paymentSaveService.save(payment);
refundPay(payment);
}
return true;
}

public void refundPayByUser(User user, String orderId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.postgraduate.domain.payment.domain.entity;

import com.postgraduate.domain.payment.domain.entity.constant.Status;
import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand All @@ -24,10 +24,10 @@ public class Payment {
private Long paymentId;

@ManyToOne(fetch = FetchType.LAZY)
private Salary salary;
private User user;

@ManyToOne(fetch = FetchType.LAZY)
private User user;
private Senior senior;

@Column(nullable = false)
private int pay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

public interface PaymentRepository extends JpaRepository<Payment, Long>, PaymentDslRepository {
Optional<Payment> findByUserAndOrderIdAndStatus(User user, String orderId, Status status);
Optional<Payment> findBySalary_SeniorAndOrderIdAndStatus(Senior senior, String orderId, Status status);
Optional<Payment> findBySeniorAndOrderIdAndStatus(Senior senior, String orderId, Status status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public Payment byUserAndOrderId(User user, String orderId) {
}

public Payment bySeniorAndOrderId(Senior senior, String orderId) {
return paymentRepository.findBySalary_SeniorAndOrderIdAndStatus(senior, orderId, DONE).orElseThrow(PaymentNotFoundException::new);
return paymentRepository.findBySeniorAndOrderIdAndStatus(senior, orderId, DONE).orElseThrow(PaymentNotFoundException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,17 @@ public class PaymentController {
private String redirectUri;
@Value("${payple.redirect-uri-dev}")
private String redirectUriDev;
@Value("${payple.cancel-redirect-uri}")
private String cancelRedirectUri;
@Value("${payple.cancel-redirect-uri-dev}")
private String cancelRedirectUriDev;

@PostMapping("/payple/result")
public void resultGet(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException {
if (paymentManageUseCase.savePay(request)) {
response.sendRedirect(redirectUri + request.PCD_PAY_OID());
return;
}
Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS());
response.sendRedirect(cancelRedirectUri + seniorId);
paymentManageUseCase.savePay(request);
response.sendRedirect(redirectUri + request.PCD_PAY_OID());
}

@PostMapping("/payple/dev/result")
public void resultGetWithDev(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException {
if (paymentManageUseCase.savePay(request)) {
response.sendRedirect(redirectUriDev + request.PCD_PAY_OID());
return;
}
Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS());
response.sendRedirect(cancelRedirectUriDev + seniorId);
paymentManageUseCase.savePay(request);
response.sendRedirect(redirectUriDev + request.PCD_PAY_OID());
}

@PostMapping("/webhook")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static Salary mapToSalary(Senior senior, LocalDate salaryDate, Account ac
.build();
}

public static SalaryDetails mapToSalaryDetail(Salary salary, Mentoring mentoring) {
public static SalaryDetails mapToSalaryDetail(Mentoring mentoring) {
Salary salary = mentoring.getSalary();
User user = mentoring.getUser();
return new SalaryDetails(
user.getProfile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SalaryDetailsResponse getSalaryDetail(User user, Boolean status) {
Senior senior = seniorGetService.byUser(user);
List<Mentoring> mentorings = mentoringGetService.bySeniorAndSalaryStatus(senior, status);
List<SalaryDetails> salaryDetails = mentorings.stream()
.map(mentoring -> SalaryMapper.mapToSalaryDetail(mentoring.getPayment().getSalary(), mentoring))
.map(SalaryMapper::mapToSalaryDetail)
.toList();
return new SalaryDetailsResponse(salaryDetails);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.postgraduate.domain.salary.domain.entity;

import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.senior.domain.entity.Senior;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand All @@ -10,7 +9,6 @@

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

@Entity
@Builder
Expand All @@ -29,9 +27,6 @@ public class Salary {
@ManyToOne(fetch = FetchType.LAZY)
private Senior senior;

@OneToMany(mappedBy = "salary", cascade = CascadeType.ALL)
private List<Payment> payments;

@Builder.Default
@Column(nullable = false)
private int totalAmount = 0;
Expand Down
Loading

0 comments on commit 35c8c0b

Please sign in to comment.