Skip to content

Commit

Permalink
Fix: errors on withdrawal and deposit on deactivated account
Browse files Browse the repository at this point in the history
  • Loading branch information
GreRut committed Nov 11, 2024
1 parent 626285a commit 89fb268
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions EventSourcing/AccountAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ private void Apply(DepositEvent deposit)
{
if (AccountId == null)
throw new AccountNotCreatedException("128 ERROR_ACCOUNT_UNINSTANTIATED");
if (Status == AccountStatus.Disabled)
throw new AccountDisabledException("344 ERROR_TRANSACTION_REJECTED_ACCOUNT_DEACTIVATED");
if (deposit.Amount > Balance)
throw new MaxBalanceExceeded("281 ERROR_BALANCE_SUCCEED_MAX_BALANCE");
else
Expand All @@ -75,6 +77,8 @@ private void Apply(WithdrawalEvent withdrawal)
{
if (AccountId == null)
throw new AccountNotCreatedException("128 ERROR_ACCOUNT_UNINSTANTIATED");
if (Status == AccountStatus.Disabled)
throw new Exception("344 ERROR_TRANSACTION_REJECTED_ACCOUNT_DEACTIVATED");
if (withdrawal.amount > Balance)
throw new MaxBalanceExceeded("285 ERROR_BALANCE_IN_NEGATIVE");
else
Expand Down
3 changes: 3 additions & 0 deletions EventSourcing/Exceptions/AccountDisabledException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace EventSourcing.Exceptions;

public class AccountDisabledException(string message) : InvalidOperationException(message);

0 comments on commit 89fb268

Please sign in to comment.