Skip to content

Commit

Permalink
#19 계좌를 존재여부 + 블락여부로 검증 후 받아오는 validateAccount메소드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Yong99 committed Jan 29, 2024
1 parent cfcc46f commit a7aac0a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/eum/bank/service/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public APIResponse<?> createAccount(String password) {
.password(passwordEncoder.encode(password))
.totalBudget(0L)
.availableBudget(0L)
.isBlocked(false)
.build();

accountRepository.save(account);
Expand Down Expand Up @@ -77,9 +78,18 @@ public Boolean validateAccountNumber(String accountNumber) {
return true;
}

// 계좌 검증 (계좌 존재여부 + 블락 여부)
public Account validateAccount(String accountNumber) {
Account account = accountRepository.findByAccountNumber(accountNumber).orElseThrow(() -> new IllegalArgumentException("Invalid account number : " + accountNumber));
if(account.getIsBlocked()){
throw new IllegalArgumentException("Blocked account : " + accountNumber);
}
return account;
}

// 계좌번호와 비밀번호로 계좌 조회
public APIResponse<AccountResponseDTO.AccountInfo> getAccount(String accountNumber, String password) {
Account account = accountRepository.findByAccountNumber(accountNumber).orElseThrow(() -> new IllegalArgumentException("Invalid account number"));
Account account = this.validateAccount(accountNumber);

// 비밀번호 검증
if (!passwordEncoder.matches(password, account.getPassword())) {
Expand All @@ -100,8 +110,8 @@ public APIResponse<AccountResponseDTO.AccountInfo> getAccount(String accountNumb
// 5. 통합 거래내역 생성, 각 계좌 거래내역 생성
@Transactional
public APIResponse<?> transfer(String senderAccountNumber, String receiverAccountNumber, Long amount, String password, String transferType) {
Account senderAccount = accountRepository.findByAccountNumber(senderAccountNumber).orElseThrow(() -> new IllegalArgumentException("Invalid account number"));
Account receiverAccount = accountRepository.findByAccountNumber(receiverAccountNumber).orElseThrow(() -> new IllegalArgumentException("Invalid account number"));
Account senderAccount = this.validateAccount(senderAccountNumber);
Account receiverAccount = this.validateAccount(receiverAccountNumber);

// 비밀번호 검증
if (!passwordEncoder.matches(password, senderAccount.getPassword())) {
Expand Down

0 comments on commit a7aac0a

Please sign in to comment.