diff --git a/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/controller/AdmWithdrawController.java b/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/controller/AdmWithdrawController.java index f429a90..70b5289 100644 --- a/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/controller/AdmWithdrawController.java +++ b/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/controller/AdmWithdrawController.java @@ -1,9 +1,11 @@ package com.example.mutbooks.app.withdraw.controller; +import com.example.mutbooks.app.base.security.dto.MemberContext; import com.example.mutbooks.app.withdraw.entity.WithdrawApply; import com.example.mutbooks.app.withdraw.service.WithdrawService; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -37,4 +39,16 @@ public String withdraw(@PathVariable long withdrawApplyId) { return "redirect:/adm/withdraw/applyList"; } + + // 출금 취소(관리자) + @PreAuthorize("hasAuthority('ADMIN')") + @PostMapping("/cancel/{withdrawApplyId}") + public String cancel( + @PathVariable long withdrawApplyId, + @AuthenticationPrincipal MemberContext memberContext + ) { + withdrawService.cancelByAdmin(memberContext.getUsername(), withdrawApplyId); + // 출금 신청 내역 페이지로 리다이렉트 + return "redirect:/withdraw/applyList"; + } } diff --git a/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/service/WithdrawService.java b/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/service/WithdrawService.java index 674cff1..c7885e2 100644 --- a/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/service/WithdrawService.java +++ b/3Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/withdraw/service/WithdrawService.java @@ -71,12 +71,33 @@ public void withdraw(long id) { withdrawApply.setWithdrawDone(); } + // 사용자 본인 출금 취소 @Transactional public void cancel(String username, long id) { WithdrawApply withdrawApply = findById(id); Member member = memberService.findByUsername(username); - // 예치금 환불 + + if(canCancel(member, withdrawApply)) { + memberService.addCash(member, withdrawApply.getPrice(), "출금취소__캐시"); + withdrawApply.setCancelDone("사용자 취소"); + } + } + + // 관리자에 의한 출금 취소 + @Transactional + public void cancelByAdmin(String username, long id) { + WithdrawApply withdrawApply = findById(id); + Member member = memberService.findByUsername(username); + memberService.addCash(member, withdrawApply.getPrice(), "출금취소__캐시"); - withdrawApply.setCancelDone("사용자 취소"); + withdrawApply.setCancelDone("관리자 취소"); + } + + // 취소 권한 검증 + public boolean canCancel(Member member, WithdrawApply withdrawApply) { + if(!member.getId().equals(withdrawApply.getApplicant().getId())) { + throw new RuntimeException("해당 출금 신청 내역의 취소 권한이 없습니다."); + } + return true; } } diff --git a/3Week_Mission/mutbooks/src/main/resources/templates/adm/withdraw/apply_list.html b/3Week_Mission/mutbooks/src/main/resources/templates/adm/withdraw/apply_list.html index 35bf0cc..1eb20b8 100644 --- a/3Week_Mission/mutbooks/src/main/resources/templates/adm/withdraw/apply_list.html +++ b/3Week_Mission/mutbooks/src/main/resources/templates/adm/withdraw/apply_list.html @@ -23,6 +23,7 @@