Skip to content

Commit

Permalink
Merge pull request #129 from Hanaro-trip-together-bank/feature/teamMe…
Browse files Browse the repository at this point in the history
…mber

feat: 입출금 기능 수정
  • Loading branch information
yubin-im authored Jun 5, 2024
2 parents d2ef8c1 + 13da654 commit 707d9aa
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public List<AccountsResDto> accounts(@RequestBody Map<String, Long> memberIdxMap
return accountService.accounts(memberIdx);
}

// 계좌 입금
// 계좌 입출금
@PutMapping("/account/deposit")
public void depositAcc(@RequestBody UpdateAccBalanceReq updateAccBalanceReq) {
accountService.depositAcc(updateAccBalanceReq);
}

// 계좌 출금
@PutMapping("/account/withdraw")
public void withdrawAcc(@RequestBody UpdateAccBalanceReq updateAccBalanceReq) {
accountService.withdrawAcc(updateAccBalanceReq);
}
// @PutMapping("/account/withdraw")
// public void withdrawAcc(@RequestBody UpdateAccBalanceReq updateAccBalanceReq) {
// accountService.withdrawAcc(updateAccBalanceReq);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

@Getter
public class UpdateAccBalanceReq {
private Long accIdx;
private Long depositAccIdx; // 입금 계좌
private Long withdrawAccIdx; // 출금 계좌
private BigDecimal amount;
private String memo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public interface AccountService {
// 전체 계좌 조회 (계좌 선택 기능)
List<AccountsResDto> accounts(Long memberIdx);

// 계좌 입금
// 계좌 입출금
void depositAcc(UpdateAccBalanceReq updateAccBalanceReq);

// 계좌 출금
void withdrawAcc(UpdateAccBalanceReq updateAccBalanceReq);
// void withdrawAcc(UpdateAccBalanceReq updateAccBalanceReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,33 @@ public List<AccountsResDto> accounts(Long memberIdx) {
return accountsResDtos;
}

// 계좌 입금
// 계좌 입출금
@Transactional
@Override
public void depositAcc(UpdateAccBalanceReq updateAccBalanceReq) {
Account account = accountRepository.findById(updateAccBalanceReq.getAccIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.ACCOUNT_NOT_FOUND));
// 계좌 입금
Account depositAcc = accountRepository.findById(updateAccBalanceReq.getDepositAccIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.ACCOUNT_NOT_FOUND));

account.updateAccBalance(account.getAccBalance().add(updateAccBalanceReq.getAmount()));
account.updateModifiedAt(LocalDateTime.now());
accountRepository.save(account);
}
depositAcc.updateAccBalance(depositAcc.getAccBalance().add(updateAccBalanceReq.getAmount()));
depositAcc.updateModifiedAt(LocalDateTime.now());
accountRepository.save(depositAcc);

// 계좌 출금
@Transactional
@Override
public void withdrawAcc(UpdateAccBalanceReq updateAccBalanceReq) {
Account account = accountRepository.findById(updateAccBalanceReq.getAccIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.ACCOUNT_NOT_FOUND));
// 계좌 출금
Account withdrawAcc = accountRepository.findById(updateAccBalanceReq.getWithdrawAccIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.ACCOUNT_NOT_FOUND));

account.updateAccBalance(account.getAccBalance().subtract(updateAccBalanceReq.getAmount()));
account.updateModifiedAt(LocalDateTime.now());
accountRepository.save(account);
withdrawAcc.updateAccBalance(withdrawAcc.getAccBalance().subtract(updateAccBalanceReq.getAmount()));
withdrawAcc.updateModifiedAt(LocalDateTime.now());
accountRepository.save(withdrawAcc);
}

// 계좌 출금
// @Transactional
// @Override
// public void withdrawAcc(UpdateAccBalanceReq updateAccBalanceReq) {
// Account account = accountRepository.findById(updateAccBalanceReq.getAccIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.ACCOUNT_NOT_FOUND));
//
// account.updateAccBalance(account.getAccBalance().subtract(updateAccBalanceReq.getAmount()));
// account.updateModifiedAt(LocalDateTime.now());
// accountRepository.save(account);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class ManageTeamResDto {
private String accNumber;
private BigDecimal accBalance;
private Boolean alarmStatus;
private Long accIdx;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public ManageTeamResDto manageTeam(ManageTeamReqDto manageTeamReqDto) {
.accNumber(account.getAccNumber())
.accBalance(account.getAccBalance())
.alarmStatus(member.getAlarmStatus())
.accIdx(account.getAccIdx())
.build();

return manageTeamResDto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void testManageTeam() {
assertEquals(account.getAccNumber(), result.getAccNumber());
assertEquals(account.getAccBalance(), result.getAccBalance());
assertEquals(member.getAlarmStatus(), result.getAlarmStatus());
assertEquals(account.getAccIdx(), result.getAccIdx());

verify(teamRepository, times(1)).findById(teamIdx);
}
Expand Down

0 comments on commit 707d9aa

Please sign in to comment.