Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 자바스크립트기초문법
- spring
- 자바
- js
- 구글 oauth
- Spring Boot
- 웹
- 구글캘린더api
- 자바스크립트기초
- 마이바티스
- 기초코딩
- react
- 스프링부트
- 자바스크립트 기초
- Javascript
- javaspring
- 코딩
- CSS
- 리액트초기세팅
- springboot
- 웹앱
- mybatis
- 전자정부 서버세팅
- HTML
- 처음만나는자바스크립트
- java
- 자바스크립트
- 기초 코딩
- 리액트세팅
- 리액트프로젝트세팅
Archives
- Today
- Total
인생 디벨로퍼
[Bank App] 10강 출금하기 본문
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 |