Skip to content

Commit

Permalink
feat: 송금 기능 구현 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Apr 15, 2023
1 parent a1df571 commit 658bce4
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
12 changes: 6 additions & 6 deletions firstSeminarAdvancedAssignment/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
- [X] 입금 기능
- [X] 계좌번호와 입금액 입력 시, 입금
+ [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
- [ ] 송금 기능
- [ ] 계좌번호 / 비밀번호 / 송금할 계좌번호 / 송금할 금액 입력 시, 송금
+ [ ] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
+ [ ] ⚠️ 잘못된 비밀번호 입력 시, 예외발생
+ [ ] ⚠️ 존재하지 않는 송금 계좌번호 입력 시, 예외 발생
+ [ ] ⚠️ 계좌 내의 금액이 출금할 금액보다 적을 시, 예외 발생
- [X] 송금 기능
- [X] 계좌번호 / 비밀번호 / 송금할 계좌번호 / 송금할 금액 입력 시, 송금
+ [X] ⚠️ 존재하지 않는 계좌번호 입력 시, 예외발생
+ [X] ⚠️ 잘못된 비밀번호 입력 시, 예외발생
+ [X] ⚠️ 존재하지 않는 송금 계좌번호 입력 시, 예외 발생
+ [X] ⚠️ 계좌 내의 금액이 출금할 금액보다 적을 시, 예외 발생


<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public void depositMoneyIntoAccount() {

int nowAmount = clientService.depositIntoAccount(inputView.inputAccountNumber(), inputView.inputDepositMoney());
outputView.printAmountAfterDeposit(nowAmount);
}

public void transferMoneyToAnotherAccount() {

int remainAmount = clientService.transferMoney(inputView.inputAccountNumber(), inputView.inputPassword(), inputView.inputAnotherAccountNumber(), inputView.inputTransferMoneyAmount());
outputView.printRemainAmountAfterTransferMessage(remainAmount);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sopt.org.firstSeminarAdvancedAssignment.domain;

import static sopt.org.firstSeminarAdvancedAssignment.view.TextData.WRONG_ACCOUNT_NUMBER_FORMAT_ERROR_MESSAGE;
import static sopt.org.firstSeminarAdvancedAssignment.view.TextData.WRONG_TRANSFER_AMOUNT_ERROR_MESSAGE;

public class Client {

Expand Down Expand Up @@ -62,6 +63,12 @@ private void checkAccountNumberLength(String[] seperatedAccountNumber) {
}
}

public void checkAccountBalanceToTransfer(int transferAmount) {
if (this.amount < transferAmount) {
throw new IllegalArgumentException(WRONG_TRANSFER_AMOUNT_ERROR_MESSAGE);
}
}

public int withdraw(int withdrawAmount) {
this.amount -= withdrawAmount;
return this.amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ public int deposit(String accountNumber, int depositAmount) {
return amountAfterDeposit;
}

public int transfer(String accountNumber, String password, String anotherAccountNumber, int transferAmount) {
validateIsExistAccountNumber(accountNumber);
Client fromClient = clientDB.get(accountNumber);
validateClientPassword(password, fromClient); //Client 도메인 측으로 넘겨야하는 검증 기능

fromClient.checkAccountBalanceToTransfer(transferAmount);
int remainAmount = fromClient.withdraw(transferAmount);

validateIsExistAccountNumber(anotherAccountNumber);
Client toClient = clientDB.get(anotherAccountNumber);

toClient.deposit(transferAmount);

return remainAmount;
}


private void validateIsExistAccountNumber(String clientAccountNumber) {
boolean isAccountExist = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public int depositIntoAccount(String accountNumber, int depositAmount) {
return amountAfterDeposit;
}

public int transferMoney(String accountNumber, String password, String anotherAccountNumber, int transferAmount) {
int remainAmountAfterTransfer = clientRepository.transfer(accountNumber, password, anotherAccountNumber, transferAmount);

return remainAmountAfterTransfer;
}

private void validateAccountBalanceAmount(int amount, int accountBalance) {
if(accountBalance < amount) {
throw new IllegalArgumentException(WRONG_ACCOUNT_BALANCE_AMOUNT_ERROR_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ public int inputWithdrawAccount() {
}

public int inputDepositMoney() {
outputView.printDepositAmountMessage();
outputView.printDepositMoneyAmountMessage();
return inputInt();
}

public String inputAnotherAccountNumber() {
outputView.printAnotherAccountToTransferMoneyMessage();
return inputString();
}

public int inputTransferMoneyAmount() {
outputView.printTransferAmountMessage();
return inputInt();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,29 @@ public void printDepositIntoAccountMessage() {
System.out.println("입금을 위해 계좌번호를 입력해주세요.");
}

public void printDepositAmountMessage() {
public void printDepositMoneyAmountMessage() {
System.out.println("입금하실 금액을 입력해주세요.");
}

public void printAmountAfterDeposit(int amount) {
System.out.println("입금 후 계좌 내 금액은 " + amount + "원 입니다.");
}

//송금 메세지
public void printAnotherAccountToTransferMoneyMessage() {
System.out.println("돈을 송금할 계좌번호를 입력해주세요.");
}

public void printTransferAmountMessage() {
System.out.println("송금하실 금액을 입력해주세요.");
}

public void printRemainAmountAfterTransferMessage(int amount) {
System.out.println("송금이 완료되었습니다.");
System.out.println("송금 후 잔액은 " + amount + "원 입니다.");
}


//기본 메세지
public void printInputClientNameMessage() {
System.out.println("이름을 입력해주세요.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class TextData {
public static final String WRONG_ACCOUNT_NUMBER_ERROR_MESSAGE = "존재하지 않는 계좌번호입니다. 다시 시도해주세요.";
public static final String WRONG_ACCOUNT_NUMBER_FORMAT_ERROR_MESSAGE = "계좌번호 형식이 잘못되었습니다. 'Integer-Integer-Integer' 형식으로 입력해주세요.";
public static final String WRONG_ACCOUNT_BALANCE_AMOUNT_ERROR_MESSAGE = "입력하신 금액이 계좌 내의 잔액보다 많습니다. 다시 시도해주세요.";
public static final String WRONG_TRANSFER_AMOUNT_ERROR_MESSAGE = "계좌 내의 잔액이 송금하실 금액보다 적습니다.";

}

0 comments on commit 658bce4

Please sign in to comment.