인생 디벨로퍼

[Bank App] 10강 출금하기 본문

Project/개인 Project - Bank App

[Bank App] 10강 출금하기

뫄뫙뫄 2023. 6. 16. 17:02
728x90

Dto 만들기

package shop.mtcoding.bankapp.dto.account;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class AccountWithdrawReqDto {
    private Long amount;
    private String wAccountNumber;
    private String wAccountPassword;
}

controller

@PostMapping("/account/withdraw")
    public String withdraw(AccountWithdrawReqDto accountWithdrawReqDto) {
        if (accountWithdrawReqDto.getAmount() == null) {
            throw new CustomException("amount를 입력해주세요", HttpStatus.BAD_REQUEST);
        }
        if (accountWithdrawReqDto.getAmount().longValue() <= 0) {
            throw new CustomException("출금액이 0원 이하일 수 없습니다.", HttpStatus.BAD_REQUEST);
        }
        if (accountWithdrawReqDto.getWAccountNumber() == null || accountWithdrawReqDto.getWAccountNumber().isEmpty()) {
            throw new CustomException("계좌번호를 입력해 주세요", HttpStatus.BAD_REQUEST);
        }
        if (accountWithdrawReqDto.getWAccountPassword() == null
                || accountWithdrawReqDto.getWAccountPassword().isEmpty()) {
            throw new CustomException("계좌 비밀번호를 입력해 주세요", HttpStatus.BAD_REQUEST);
        }

        int accoutId = accountService.계좌출금(accountWithdrawReqDto);
        return "redirect:/account" + accoutId;
    }

서비스에서 계좌출금시 해야할 일

  • 계좌존재 여부
  • 계좌 패스워드 확인
  • 잔액 확인
  • 출금
  • 히스토리 (거래내역)
  • 해당 계좌 ID 리턴

 


service

부정연산자 "!" 사용

 

(기존 잔액 - 출금액) 연산후, accountPS 에 set 해주고,

accountPS 를 account 테이블에 update

거래내역 남기기. 


결과

 

 

제대로 입력해줘보자..

상세보기 페이지로 넘어간다.

아직 상세보기 페이지를 만들지 않아, 데이터는 변경 x 

대신

메인페이지에 계좌 잔액이 변경된것 확인 가능.

h2 로 확인 가능. 히스토리도 잘 들어갔다!

728x90

'Project > 개인 Project - Bank App' 카테고리의 다른 글

[Bank App] 12강 이체하기  (0) 2023.06.16
[Bank App] 11강 입금하기  (0) 2023.06.16
[Bank App] 9강 계좌목록보기  (1) 2023.06.16
[Bank App] 8강 계좌생성하기  (0) 2023.06.14
[Bank App] 7강 로그인 만들기  (0) 2023.06.14