diff --git a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminPaymentUseCase.java b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminPaymentUseCase.java index bb04fa7d..e66ab04c 100644 --- a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminPaymentUseCase.java +++ b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminPaymentUseCase.java @@ -3,8 +3,10 @@ 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; @@ -19,6 +21,7 @@ public class AdminPaymentUseCase { private final PaymentGetService paymentGetService; private final MentoringGetService mentoringGetService; + private final PaymentManageUseCase paymentManageUseCase; public List paymentInfos() { List all = paymentGetService.all(); @@ -31,4 +34,8 @@ public List paymentInfos() { }) .toList(); } + + public void refundPayment(User user, Long paymentId) { + paymentManageUseCase.refundPayByAdmin(user, paymentId); + } } diff --git a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSalaryUseCase.java b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSalaryUseCase.java index 005647c1..e386a9d1 100644 --- a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSalaryUseCase.java +++ b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSalaryUseCase.java @@ -16,6 +16,7 @@ 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; @@ -31,6 +32,7 @@ public class AdminSalaryUseCase { public List salaryInfos() { List all = salaryGetService.findAll(); return all.stream() + .filter(salary -> getStatus(salary) == DONE) .map(salary -> { if (salary.getAccountNumber() == null) return mapToSalaryResponse(salary.getSenior(), salary); @@ -42,7 +44,7 @@ public List salaryInfos() { public SalaryInfo seniorSalary(Long seniorId) { Senior senior = seniorGetService.bySeniorId(seniorId); - Salary salary = salaryGetService.bySenior(senior); + Salary salary = salaryGetService.bySeniorLastWeek(senior); SalaryStatus status = getStatus(salary); if (status != YET) throw new SalaryNotYetException(); diff --git a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java index f1d276ce..d2fe6c0b 100644 --- a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java +++ b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java @@ -36,7 +36,7 @@ public List allSenior() { List seniors = seniorGetService.allSeniorId(); return seniors.stream() .map(senior -> { - Salary salary = salaryGetService.bySenior(senior); + Salary salary = salaryGetService.bySeniorLastWeek(senior); SalaryStatus salaryStatus = getStatus(salary); Optional wish = wishGetService.byUser(senior.getUser()); return mapToSeniorInfo(senior, salaryStatus, wish.isPresent()); diff --git a/src/main/java/com/postgraduate/domain/adminssr/presentation/AdminWithThymeLeafController.java b/src/main/java/com/postgraduate/domain/adminssr/presentation/AdminWithThymeLeafController.java index 912fa633..7dc439df 100644 --- a/src/main/java/com/postgraduate/domain/adminssr/presentation/AdminWithThymeLeafController.java +++ b/src/main/java/com/postgraduate/domain/adminssr/presentation/AdminWithThymeLeafController.java @@ -3,7 +3,6 @@ import com.postgraduate.domain.admin.application.dto.*; 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.adminssr.application.dto.req.Login; import com.postgraduate.domain.adminssr.application.usecase.*; @@ -51,27 +50,6 @@ public String seniorInfo(Model model) { return "adminSenior"; } - @GetMapping("/userInfo") - public String userInfo(Model model) { - List userInfos = adminUserUseCase.userInfos(); - model.addAttribute("userInfos", userInfos); - return "adminUser"; - } - - @GetMapping("/paymentInfo") - public String paymentInfo(Model model) { - List paymentInfos = adminPaymentUseCase.paymentInfos(); - model.addAttribute("paymentInfos", paymentInfos); - return "adminPayment"; - } - - @GetMapping("/salaryInfo") - public String salaryInfo(Model model) { - List salaryInfos = adminSalaryUseCase.salaryInfos(); - model.addAttribute("salaryInfo", salaryInfos); - return "adminSalary"; - } - @GetMapping("/certification/{seniorId}") public String certification(@PathVariable Long seniorId, Model model) { CertificationDetailsResponse certification = adminSeniorUseCase.getCertification(seniorId); @@ -104,6 +82,13 @@ public String refundMentoring(@AuthenticationPrincipal User user, @PathVariable return "adminEmpty"; } + @GetMapping("/salaryInfo") + public String salaryInfo(Model model) { + List salaryInfos = adminSalaryUseCase.salaryInfos(); + model.addAttribute("salaryInfo", salaryInfos); + return "adminSalary"; + } + @GetMapping("/salary/{seniorId}") public String seniorSalaryInfo(@PathVariable Long seniorId, Model model) { SalaryInfo salaryInfo = adminSalaryUseCase.seniorSalary(seniorId); @@ -117,6 +102,12 @@ public String salaryDone(@PathVariable Long salaryId) { return "adminEmpty"; } + @PostMapping("/wish/done/{wishId}") + public String wishDone(@PathVariable Long wishId) { + adminUserUseCase.wishDone(wishId); + return "adminEmpty"; + } + @GetMapping("/user/matching/{userId}") public String userMatching(@PathVariable Long userId, Model model) { WishResponse wishResponse = adminUserUseCase.wishInfo(userId); @@ -124,12 +115,6 @@ public String userMatching(@PathVariable Long userId, Model model) { return "userWish"; } - @PostMapping("/wish/done/{wishId}") - public String wishDone(@PathVariable Long wishId) { - adminUserUseCase.wishDone(wishId); - return "adminEmpty"; - } - @GetMapping("/user/mentoring/{userId}") public String userMentoring(@PathVariable Long userId, Model model) { MentoringManageResponse mentoringInfos = adminMentoringUseCase.userMentoringInfos(userId); @@ -137,10 +122,23 @@ public String userMentoring(@PathVariable Long userId, Model model) { return "userMentoring"; } - @GetMapping("/payment/mentoring/{paymentId}") - public String paymentMentoring(@PathVariable Long paymentId, Model model) { - MentoringWithPaymentResponse mentoringInfo = adminMentoringUseCase.paymentMentoringInfo(paymentId); - model.addAttribute("mentoringInfo", mentoringInfo); - return "paymentMentoring"; + @GetMapping("/userInfo") + public String userInfo(Model model) { + List userInfos = adminUserUseCase.userInfos(); + model.addAttribute("userInfos", userInfos); + return "adminUser"; + } + + @GetMapping("/paymentInfo") + public String paymentInfo(Model model) { + List paymentInfos = adminPaymentUseCase.paymentInfos(); + model.addAttribute("paymentInfos", paymentInfos); + return "adminPayment"; + } + + @PostMapping("/payment/refund/{paymentId}") + public String refundPayment(@AuthenticationPrincipal User user, @PathVariable Long paymentId) { + adminPaymentUseCase.refundPayment(user, paymentId); + return "adminEmpty"; } } diff --git a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java index bf2750c3..1958dd83 100644 --- a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java +++ b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java @@ -35,6 +35,12 @@ public Salary bySenior(Senior senior) { .orElseThrow(SalaryNotFoundException::new); } + public Salary bySeniorLastWeek(Senior senior) { + LocalDate salaryDate = SalaryUtil.getSalaryDate().minusDays(7); + return salaryRepository.findBySeniorAndSalaryDate(senior, salaryDate) + .orElseThrow(SalaryNotFoundException::new); + } + public Page findDistinctSeniors(String search, Integer page) { page = page == null ? 1 : page; Pageable pageable = PageRequest.of(page - 1, ADMIN_PAGE_SIZE); diff --git a/src/main/resources/templates/adminMain.html b/src/main/resources/templates/adminMain.html index 8d84756e..31f7b94c 100644 --- a/src/main/resources/templates/adminMain.html +++ b/src/main/resources/templates/adminMain.html @@ -286,6 +286,27 @@ }; xhr.send(); } + + function refundPayment(paymentId) { + if (confirm("정말 환불하겠습니까??") == true){ //확인 + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/adminServer/payment/refund/" + paymentId, true); + xhr.setRequestHeader("Authorization", "Bearer " + accessToken); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + document.getElementById("output").innerHTML = xhr.responseText; + } else { + localStorage.removeItem("accessToken"); + localStorage.removeItem("refreshToken"); + } + } + }; + xhr.send(); + }else{ //취소 + return false; + } + } diff --git a/src/main/resources/templates/adminPayment.html b/src/main/resources/templates/adminPayment.html index 6d96a756..ab554f2b 100644 --- a/src/main/resources/templates/adminPayment.html +++ b/src/main/resources/templates/adminPayment.html @@ -26,6 +26,7 @@ 전화번호 결제일시 멘토링정보 + 환불/취소 결제상태 @@ -36,6 +37,7 @@ phoneNumber createdAt + status diff --git a/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java b/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java index 405d88f0..c074fcac 100644 --- a/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java +++ b/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java @@ -9,6 +9,7 @@ import com.postgraduate.domain.available.domain.repository.AvailableRepository; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.repository.SalaryRepository; +import com.postgraduate.domain.salary.util.SalaryUtil; import com.postgraduate.domain.senior.application.dto.req.*; import com.postgraduate.domain.senior.domain.entity.Info; import com.postgraduate.domain.senior.domain.entity.Profile; @@ -31,12 +32,14 @@ import org.junit.jupiter.params.provider.EmptySource; import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.mockito.BDDMockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; import java.io.IOException; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -47,6 +50,7 @@ import static java.lang.Boolean.TRUE; import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;