Skip to content

Commit

Permalink
Fix: 출금 관리자 페이지 Whitelabel Error Page 발생 버그 수정 (#81)
Browse files Browse the repository at this point in the history
* feat: 출금 요청할때 요청한 사람이 시니또인지 검증하는 로직 추가

* fix: 만에 하나 시니또가 존재하지 않으면 예외를 던지는게 아니라 임시 시니또 객체 생성하는것으로 변경(관리자 페이지 Whitelabel Error Page 방지)
  • Loading branch information
zzoe2346 authored Oct 17, 2024
1 parent e7b3a4d commit e4bc19a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.example.sinitto.point.controller;

import com.example.sinitto.member.entity.Member;
import com.example.sinitto.member.entity.Sinitto;
import com.example.sinitto.member.exception.MemberNotFoundException;
import com.example.sinitto.member.repository.MemberRepository;
import com.example.sinitto.point.dto.PointLogWithBankInfo;
import com.example.sinitto.point.dto.PointLogWithDepositMessage;
import com.example.sinitto.point.entity.PointLog;
import com.example.sinitto.point.service.PointAdminService;
import com.example.sinitto.sinitto.exception.SinittoNotFoundException;
import com.example.sinitto.sinitto.repository.SinittoRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -24,12 +21,10 @@ public class PointAdminController {

private final PointAdminService pointAdminService;
private final MemberRepository memberRepository;
private final SinittoRepository sinittoRepository;

public PointAdminController(PointAdminService pointAdminService, MemberRepository memberRepository, SinittoRepository sinittoRepository) {
public PointAdminController(PointAdminService pointAdminService, MemberRepository memberRepository) {
this.pointAdminService = pointAdminService;
this.memberRepository = memberRepository;
this.sinittoRepository = sinittoRepository;
}

@GetMapping("/admin/point/charge")
Expand Down Expand Up @@ -81,24 +76,8 @@ public String changeToFail(@PathVariable Long pointLogId) {
@GetMapping("/admin/point/withdraw")
public String showAllWithdrawRequest(Model model) {

List<PointLog> pointLogs = pointAdminService.readAllPointWithdrawRequest();
List<PointLogWithBankInfo> logWithBankInfos = new ArrayList<>();
List<PointLogWithBankInfo> logWithBankInfos = pointAdminService.getPointLogWithBankInfo();

for (PointLog pointLog : pointLogs) {
Sinitto sinitto = sinittoRepository.findByMemberId(pointLog.getMember().getId())
.orElseThrow(() -> new SinittoNotFoundException("시니또를 찾을 수 없습니다"));

PointLogWithBankInfo pointLogWithBankInfo = new PointLogWithBankInfo(
pointLog.getId(),
pointLog.getPrice(),
pointLog.getPostTime(),
pointLog.getStatus(),
sinitto.getBankName(),
sinitto.getAccountNumber()
);

logWithBankInfos.add(pointLogWithBankInfo);
}
model.addAttribute("logWithBankInfos", logWithBankInfos);

return "point/withdraw";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package com.example.sinitto.point.service;

import com.example.sinitto.member.entity.Sinitto;
import com.example.sinitto.point.dto.PointLogWithBankInfo;
import com.example.sinitto.point.entity.Point;
import com.example.sinitto.point.entity.PointLog;
import com.example.sinitto.point.exception.PointLogNotFoundException;
import com.example.sinitto.point.repository.PointLogRepository;
import com.example.sinitto.point.repository.PointRepository;
import com.example.sinitto.sinitto.repository.SinittoRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class PointAdminService {

private final PointLogRepository pointLogRepository;
private final PointRepository pointRepository;
private final SinittoRepository sinittoRepository;

public PointAdminService(PointLogRepository pointLogRepository, PointRepository pointRepository) {
public PointAdminService(PointLogRepository pointLogRepository, PointRepository pointRepository, SinittoRepository sinittoRepository) {
this.pointLogRepository = pointLogRepository;
this.pointRepository = pointRepository;
this.sinittoRepository = sinittoRepository;
}

public List<PointLog> readAllNotCompletedPointChargeRequest() {
Expand Down Expand Up @@ -57,12 +63,6 @@ public void changeChargeLogToFail(Long pointLogId) {
pointLog.changeStatusToChargeFail();
}

@Transactional(readOnly = true)
public List<PointLog> readAllPointWithdrawRequest() {

return pointLogRepository.findAllByStatusInOrderByPostTimeDesc(List.of(PointLog.Status.WITHDRAW_REQUEST, PointLog.Status.WITHDRAW_WAITING, PointLog.Status.WITHDRAW_COMPLETE, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT));
}

@Transactional
public void changeWithdrawLogToWaiting(Long pointLogId) {

Expand Down Expand Up @@ -94,4 +94,28 @@ public void changeWithdrawLogToFail(Long pointLogId) {

pointLog.changeStatusToWithdrawFail();
}

@Transactional(readOnly = true)
public List<PointLogWithBankInfo> getPointLogWithBankInfo() {

List<PointLog> withdrawPointLogs = pointLogRepository.findAllByStatusInOrderByPostTimeDesc(List.of(PointLog.Status.WITHDRAW_REQUEST, PointLog.Status.WITHDRAW_WAITING, PointLog.Status.WITHDRAW_COMPLETE, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT));

List<PointLogWithBankInfo> logWithBankInfos = new ArrayList<>();

for (PointLog pointLog : withdrawPointLogs) {
Sinitto sinitto = sinittoRepository.findByMemberId(pointLog.getMember().getId())
.orElse(new Sinitto("등록된 계좌 없음", "등록된 계좌 없음", null));

PointLogWithBankInfo pointLogWithBankInfo = new PointLogWithBankInfo(
pointLog.getId(),
pointLog.getPrice(),
pointLog.getPostTime(),
pointLog.getStatus(),
sinitto.getBankName(),
sinitto.getAccountNumber()
);
logWithBankInfos.add(pointLogWithBankInfo);
}
return logWithBankInfos;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.sinitto.point.service;

import com.example.sinitto.callback.exception.NotSinittoException;
import com.example.sinitto.member.entity.Member;
import com.example.sinitto.member.exception.MemberNotFoundException;
import com.example.sinitto.member.repository.MemberRepository;
Expand Down Expand Up @@ -73,6 +74,10 @@ public void savePointWithdrawRequest(Long memberId, int price) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundException("요청한 멤버를 찾을 수 없습니다"));

if(!member.isSinitto()){
throw new NotSinittoException("출금 요청은 시니또만 가능합니다. 지금 요청은 시니또가 요청하지 않았습니다.");
}

Point point = pointRepository.findByMember(member)
.orElseThrow(() -> new PointNotFoundException("요청한 멤버의 포인트를 찾을 수 없습니다"));

Expand Down

0 comments on commit e4bc19a

Please sign in to comment.