본문 바로가기

Spring boot/Bank App 만들기(deployment)

Bank App 만들기 ( deployment ) - 입금 기능 만들기

생성 될 파일 확인

 

 

 

 

결과 화면 미리 보기

 

 

 

deposit.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!-- header.jsp  -->
<%@ include file="/WEB-INF/view/layout/header.jsp"%>

<!-- start of content.jsp(xxx.jsp)   -->
<div class="col-sm-8">
	<h2>입금 요청(인증)</h2>
	<h5>Bank App에 오신걸 환영합니다</h5>
	<form action="/account/deposit" method="post">
        <div class="form-group">
            <label for="amount">입금 금액:</label> <input type="number" class="form-control" placeholder="Enter amount" id="amount" name="amount" value="1000">
        </div>
        <div class="form-group">
            <label for="dAccountNumber">입금 계좌 번호:</label> <input type="text" class="form-control" placeholder="Enter account number" id="dAccountNumber" name="dAccountNumber" value="1111">
        </div>
        <div class="text-right">
            <button type="submit" class="btn btn-primary">입금</button>
        </div>
    </form>
</div>
<!-- end of col-sm-8  -->
</div>
</div>
<!-- end of content.jsp(xxx.jsp)   -->

<!-- footer.jsp  -->
<%@ include file="/WEB-INF/view/layout/footer.jsp"%>

 

 

 

 

DepositDTO
package com.tenco.bank.dto;

import lombok.Data;

@Data
public class DepositDTO {
	
	private Long amount; 
	private String dAccountNumber; 
}

 

 

 

 

입금 기능 추가
// 입금 기능 만들기 
	// 1. 계좌 존재 여부를 확인
    // 2. 본인 계좌 여부를 확인 -- 객체 상태값에서 비교
    // 3. 입금 처리 -- update
    // 4. 거래 내역 등록 -- insert(history)
	@Transactional
    public void updateAccountDeposit(DepositDTO dto, Integer principalId) {
        // 1.
        Account accountEntity = accountRepository.findByNumber(dto.getDAccountNumber());
        if (accountEntity == null) {
            throw new DataDeliveryException(Define.NOT_EXIST_ACCOUNT, HttpStatus.BAD_REQUEST);
        }
        // 2.
        accountEntity.checkOwner(principalId);
        // 3.
        accountEntity.deposit(dto.getAmount());
        accountRepository.updateById(accountEntity);
        
        // 4.
        History history = History.builder()
            .amount(dto.getAmount())
            .dAccountId(accountEntity.getId())
            .dBalance(accountEntity.getBalance())
            .wAccountId(null)
            .wBalance(null)
            .build();
        int rowResultCount = historyRepository.insert(history);
        if (rowResultCount != 1) {
            throw new DataDeliveryException(Define.FAILED_PROCESSING, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

 

 

 

 

 

accountService
// 입금 기능 만들기 
// 1. 계좌 존재 여부를 확인
// 2. 본인 계좌 여부를 확인 -- 객체 상태값에서 비교
// 3. 입금 처리 -- update
// 4. 거래 내역 등록 -- insert(history)
@Transactional
public void updateAccountDeposit(DepositDTO dto, Integer principalId) {
    // 1.
    Account accountEntity = accountRepository.findByNumber(dto.getDAccountNumber());
    if (accountEntity == null) {
        throw new DataDeliveryException(Define.NOT_EXIST_ACCOUNT, HttpStatus.BAD_REQUEST);
    }
    // 2.
    accountEntity.checkOwner(principalId);
    // 3.
    accountEntity.deposit(dto.getAmount());
    accountRepository.updateById(accountEntity);
    
    // 4.
    History history = History.builder()
        .amount(dto.getAmount())
        .dAccountId(accountEntity.getId())
        .dBalance(accountEntity.getBalance())
        .wAccountId(null)
        .wBalance(null)
        .build();
    int rowResultCount = historyRepository.insert(history);
    if (rowResultCount != 1) {
        throw new DataDeliveryException(Define.FAILED_PROCESSING, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

 

 

 

 

account.xml
	<update id="updateById">
		update account_tb set number = #{number}, password = #{password},
			balance = #{balance}, user_id = #{userId} where id = #{id}
	</update>
728x90