Skip to content

Commit

Permalink
#23 - Feat: 출금 신청 취소(관리자 기능) 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 7, 2022
1 parent 7245481 commit 79805f7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h1>출금신청 내역</h1>
<th>출금일시</th>
<th>취소일시</th>
<th>처리 상태</th>
<th>비고</th>
</tr>
</thead>

Expand All @@ -33,17 +34,30 @@ <h1>출금신청 내역</h1>
<td th:text="${withdrawApply.bankAccountNo}"></td>
<td th:text="|${withdrawApply.price} 원|"></td>
<td th:text="${#temporals.format(withdrawApply.createDate, 'yyyy-MM-dd hh:mm:ss')}"></td>
<td th:text="${#temporals.format(withdrawApply.withdrawDate, 'yyyy-MM-dd hh:mm:ss')}"></td>
<td th:text="${#temporals.format(withdrawApply.cancelDate, 'yyyy-MM-dd hh:mm:ss')}"></td>
<td>
<div th:if="${withdrawApply.withdrawDate == null}">-</div>
<div th:unless="${withdrawApply.withdrawDate == null}"
th:text="${#temporals.format(withdrawApply.withdrawDate, 'yyyy-MM-dd hh:mm:ss')}"></div>
</td>
<td>
<div th:if="${withdrawApply.cancelDate == null}">-</div>
<div th:unless="${withdrawApply.cancelDate == null}"
th:text="${#temporals.format(withdrawApply.cancelDate, 'yyyy-MM-dd hh:mm:ss')}"></div>
</td>
<th:block>
<td th:if="${withdrawApply.isAppliedStatus}">
<a href="javascript:;" onclick="$(this).next().submit();" class="btn btn-xs">출금 처리</a>
<form method="POST" th:action="@{|/adm/withdraw/${withdrawApply.id}|}" hidden>
</form>
</td>
<td th:if="${withdrawApply.isAppliedStatus}">신청완료</td>
<td th:if="${withdrawApply.isWithdrawnStatus}" class="text-blue-600">출금완료</td>
<td th:if="${withdrawApply.isCancelledStatus}" class="text-red-600">취소완료</td>
</th:block>
<td th:if="${withdrawApply.isAppliedStatus}">
<a href="javascript:;" onclick="$(this).next().submit();" class="btn btn-xs">출금 처리</a>
<form method="POST" th:action="@{|/adm/withdraw/${withdrawApply.id}|}" hidden>
</form>
<a href="javascript:;" onclick="if(confirm('정말로 취소하시겠습니가?')) $(this).next().submit();"
class="btn btn-xs">취소</a>
<form method="POST" th:action="@{|/adm/withdraw/cancel/${withdrawApply.id}|}" hidden>
</form>
</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@ <h1>출금신청 내역</h1>
<td th:text="${withdrawApply.bankAccountNo}"></td>
<td th:text="|${withdrawApply.price} 원|"></td>
<td th:text="${#temporals.format(withdrawApply.createDate, 'yyyy-MM-dd hh:mm:ss')}"></td>
<td th:text="${#temporals.format(withdrawApply.withdrawDate, 'yyyy-MM-dd hh:mm:ss')}"></td>
<td th:text="${#temporals.format(withdrawApply.cancelDate, 'yyyy-MM-dd hh:mm:ss')}"></td>
<td>
<div th:if="${withdrawApply.withdrawDate == null}">-</div>
<div th:unless="${withdrawApply.withdrawDate == null}"
th:text="${#temporals.format(withdrawApply.withdrawDate, 'yyyy-MM-dd hh:mm:ss')}"></div>
</td>
<td>
<div th:if="${withdrawApply.cancelDate == null}">-</div>
<div th:unless="${withdrawApply.cancelDate == null}"
th:text="${#temporals.format(withdrawApply.cancelDate, 'yyyy-MM-dd hh:mm:ss')}"></div>
</td>
<th:block>
<td th:if="${withdrawApply.isAppliedStatus}">신청완료</td>
<td th:if="${withdrawApply.isWithdrawnStatus}" class="text-blue-600">출금완료</td>
<td th:if="${withdrawApply.isCancelledStatus}" class="text-red-600">취소완료</td>
</th:block>
<td th:if="${withdrawApply.isAppliedStatus}">
<a href="javascript:;" onclick="$(this).next().submit();" class="btn btn-xs">취소</a>
<a href="javascript:;" onclick="if(confirm('정말로 취소하시겠습니가?')) $(this).next().submit();"
class="btn btn-xs">취소</a>
<form method="POST" th:action="@{|/withdraw/cancel/${withdrawApply.id}|}" hidden>
</form>
</td>
Expand Down

0 comments on commit 79805f7

Please sign in to comment.