Skip to content

Commit

Permalink
Fix: withdrawal method
Browse files Browse the repository at this point in the history
  • Loading branch information
GreRut committed Nov 11, 2024
1 parent 3c025af commit 433aa1d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions EventSourcing/AccountAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ private void Apply(Event accountEvent)
case DepositEvent deposit:
Apply(deposit);
break;
case WithdrawalEvent withdrawal:
Apply(withdrawal);
break;
default:
throw new EventTypeNotSupportedException("162 ERROR_EVENT_NOT_SUPPORTED");
}
Expand All @@ -65,9 +68,14 @@ private void Apply(DepositEvent deposit)
Balance += deposit.Amount;
}

private void Apply(WithdrawalEvent wihdrawal)
{
throw new NotImplementedException();
private void Apply(WithdrawalEvent withdrawal)
{
if (AccountId == null)
throw new AccountNotCreatedException("128 ERROR_ACCOUNT_UNINSTANTIATED");
if (withdrawal.amount > Balance)
throw new MaxBalanceExceeded("281 ERROR_BALANCE_SUCCEED_MAX_BALANCE");
else
Balance -= withdrawal.amount;
}

private void Apply(DeactivationEvent deactivation)
Expand Down

0 comments on commit 433aa1d

Please sign in to comment.