From 79805f7a20f4e50910c69288c9b2011a360c334a Mon Sep 17 00:00:00 2001 From: ahah525 Date: Mon, 7 Nov 2022 21:50:36 +0900 Subject: [PATCH] =?UTF-8?q?#23=20-=20Feat:=20=EC=B6=9C=EA=B8=88=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=B7=A8=EC=86=8C(=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=9E=90=20=EA=B8=B0=EB=8A=A5)=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdmWithdrawController.java | 14 ++++++++++ .../app/withdraw/service/WithdrawService.java | 25 +++++++++++++++-- .../templates/adm/withdraw/apply_list.html | 28 ++++++++++++++----- .../templates/withdraw/apply_list.html | 15 ++++++++-- 4 files changed, 70 insertions(+), 12 deletions(-) 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 @@

출금신청 내역

출금일시 취소일시 처리 상태 + 비고 @@ -33,17 +34,30 @@

출금신청 내역

- - + +
-
+
+ + +
-
+
+ - - 출금 처리 - - + 신청완료 출금완료 취소완료 + + 출금 처리 + + 취소 + + diff --git a/3Week_Mission/mutbooks/src/main/resources/templates/withdraw/apply_list.html b/3Week_Mission/mutbooks/src/main/resources/templates/withdraw/apply_list.html index 487bb9f..17e158d 100644 --- a/3Week_Mission/mutbooks/src/main/resources/templates/withdraw/apply_list.html +++ b/3Week_Mission/mutbooks/src/main/resources/templates/withdraw/apply_list.html @@ -34,15 +34,24 @@

출금신청 내역

- - + +
-
+
+ + +
-
+
+ 신청완료 출금완료 취소완료 - 취소 + 취소