@EventHandler public void on(AccountCreatedEvent event){ this.accountId = event.getAccountId(); this.accountName = event.getAccountName(); this.balance = new BigDecimal(event.getAmount()); LOGGER.info("Account {} is created with balance {}", accountId, this.balance); }
@EventHandler public void on(MoneyWithdrawnEvent event){ BigDecimal result = this.balance.subtract(new BigDecimal(event.getAmount())); if(result.compareTo(BigDecimal.ZERO)<0) LOGGER.error("Cannot withdraw more money than the balance!"); else { this.balance = result; LOGGER.info("Withdraw {} from account {}, balance result: {}", event.getAmount(), accountId, balance); } } }
@CommandHandler public BankAccount(CreateAccountCommand command){ LOGGER.debug("Construct a new BankAccount"); apply(new AccountCreatedEvent(command.getAccountId(), command.getAccountName(), command.getAmount())); }
@CommandHandler public void handle(WithdrawMoneyCommand command){ apply(new MoneyWithdrawnEvent(command.getAccountId(), command.getAmount())); }
@EventHandler public void on(AccountCreatedEvent event){ this.accountId = event.getAccountId(); this.accountName = event.getAccountName(); this.balance = new BigDecimal(event.getAmount()); LOGGER.info("Account {} is created with balance {}", accountId, this.balance); }
@EventHandler public void on(MoneyWithdrawnEvent event){ BigDecimal result = this.balance.subtract(new BigDecimal(event.getAmount())); if(result.compareTo(BigDecimal.ZERO)<0) LOGGER.error("Cannot withdraw more money than the balance!"); else { this.balance = result; LOGGER.info("Withdraw {} from account {}, balance result: {}", event.getAmount(), accountId, balance); } } }
@CommandHandler public void handle(WithdrawMoneyCommand command){ apply(new MoneyWithdrawnEvent(command.getAccountId(), command.getAmount())); }
@CommandHandler public BankAccount(CreateAccountCommand command){ LOGGER.debug("Construct a new BankAccount"); apply(new AccountCreatedEvent(command.getAccountId(), command.getAccountName(), command.getAmount())); }
@EventHandler public void on(AccountCreatedEvent event){ this.accountId = event.getAccountId(); this.accountName = event.getAccountName(); this.balance = new BigDecimal(event.getAmount()); LOGGER.info("Account {} is created with balance {}", accountId, this.balance); }
@EventHandler public void on(MoneyWithdrawnEvent event){ BigDecimal result = this.balance.subtract(new BigDecimal(event.getAmount())); if(result.compareTo(BigDecimal.ZERO)<0) LOGGER.error("Cannot withdraw more money than the balance!"); else { this.balance = result; LOGGER.info("Withdraw {} from account {}, balance result: {}", event.getAmount(), accountId, balance); } }
@CommandHandler public void handle(WithdrawMoneyCommand command){ apply(new MoneyWithdrawnEvent(command.getAccountId(), command.getAmount())); }
@CommandHandler public BankAccount(CreateAccountCommand command){ LOGGER.debug("Construct a new BankAccount"); apply(new AccountCreatedEvent(command.getAccountId(), command.getAccountName(), command.getAmount())); }