Skip to content

Commit

Permalink
Merge pull request #182 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
RAC-325 deploy : ์šด์˜ ๋ฐ˜์˜
  • Loading branch information
ywj9811 authored Mar 18, 2024
2 parents f912fed + 36052df commit 9c84d6a
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,7 @@
public class AdminPaymentUseCase {
private final PaymentGetService paymentGetService;
private final MentoringGetService mentoringGetService;
private final PaymentManageUseCase paymentManageUseCase;

public List<PaymentInfo> paymentInfos() {
List<Payment> all = paymentGetService.all();
Expand All @@ -31,4 +34,8 @@ public List<PaymentInfo> paymentInfos() {
})
.toList();
}

public void refundPayment(User user, Long paymentId) {
paymentManageUseCase.refundPayByAdmin(user, paymentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,6 +32,7 @@ public class AdminSalaryUseCase {
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);
Expand All @@ -42,7 +44,7 @@ public List<SalaryInfo> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<SeniorInfo> allSenior() {
List<Senior> seniors = seniorGetService.allSeniorId();
return seniors.stream()
.map(senior -> {
Salary salary = salaryGetService.bySenior(senior);
Salary salary = salaryGetService.bySeniorLastWeek(senior);
SalaryStatus salaryStatus = getStatus(salary);
Optional<Wish> wish = wishGetService.byUser(senior.getUser());
return mapToSeniorInfo(senior, salaryStatus, wish.isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -51,27 +50,6 @@ public String seniorInfo(Model model) {
return "adminSenior";
}

@GetMapping("/userInfo")
public String userInfo(Model model) {
List<UserInfo> userInfos = adminUserUseCase.userInfos();
model.addAttribute("userInfos", userInfos);
return "adminUser";
}

@GetMapping("/paymentInfo")
public String paymentInfo(Model model) {
List<PaymentInfo> paymentInfos = adminPaymentUseCase.paymentInfos();
model.addAttribute("paymentInfos", paymentInfos);
return "adminPayment";
}

@GetMapping("/salaryInfo")
public String salaryInfo(Model model) {
List<SalaryInfo> 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);
Expand Down Expand Up @@ -104,6 +82,13 @@ public String refundMentoring(@AuthenticationPrincipal User user, @PathVariable
return "adminEmpty";
}

@GetMapping("/salaryInfo")
public String salaryInfo(Model model) {
List<SalaryInfo> 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);
Expand All @@ -117,30 +102,43 @@ 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);
model.addAttribute("wishInfo", wishResponse);
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);
model.addAttribute("mentoringInfos", mentoringInfos);
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<UserInfo> userInfos = adminUserUseCase.userInfos();
model.addAttribute("userInfos", userInfos);
return "adminUser";
}

@GetMapping("/paymentInfo")
public String paymentInfo(Model model) {
List<PaymentInfo> 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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SeniorSalary> findDistinctSeniors(String search, Integer page) {
page = page == null ? 1 : page;
Pageable pageable = PageRequest.of(page - 1, ADMIN_PAGE_SIZE);
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/templates/adminMain.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
</script>


Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/adminPayment.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<th>์ „ํ™”๋ฒˆํ˜ธ</th>
<th>๊ฒฐ์ œ์ผ์‹œ</th>
<th>๋ฉ˜ํ† ๋ง์ •๋ณด</th>
<th>ํ™˜๋ถˆ/์ทจ์†Œ</th>
<th>๊ฒฐ์ œ์ƒํƒœ</th>
</tr>
</thead>
Expand All @@ -36,6 +37,7 @@
<td th:text="${paymentInfo.phoneNumber()}">phoneNumber</td>
<td th:text="${paymentInfo.createdAt()}">createdAt</td>
<td><button th:paymentId="${paymentInfo.paymentId()}" th:onclick="getPaymentMentoring(this.getAttribute('paymentId'))">๋ฉ˜ํ† ๋ง์ •๋ณด๋ณด๊ธฐ</button></td>
<td><button th:paymentId="${paymentInfo.paymentId()}" th:onclick="refundPayment(this.getAttribute('paymentId'))">ํ™˜๋ถˆ/์ทจ์†Œ</button></td>
<td th:text="${paymentInfo.status()}">status</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 9c84d6a

Please sign in to comment.