eventsourcing 9.3.5__py3-none-any.whl → 9.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of eventsourcing might be problematic. Click here for more details.

@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass
4
4
  from decimal import Decimal
5
+ from typing import cast
5
6
  from uuid import uuid4
6
7
 
7
8
  from eventsourcing.domain import Aggregate, AggregateCreated, AggregateEvent
@@ -13,9 +14,7 @@ class EmailAddress:
13
14
 
14
15
 
15
16
  class BankAccount(Aggregate):
16
- """
17
- Aggregate root for bank accounts.
18
- """
17
+ """Aggregate root for bank accounts."""
19
18
 
20
19
  def __init__(self, full_name: str, email_address: EmailAddress):
21
20
  self.full_name = full_name
@@ -26,9 +25,7 @@ class BankAccount(Aggregate):
26
25
 
27
26
  @classmethod
28
27
  def open(cls, full_name: str, email_address: str) -> BankAccount:
29
- """
30
- Creates new bank account object.
31
- """
28
+ """Creates new bank account object."""
32
29
  return cls._create(
33
30
  cls.Opened,
34
31
  id=uuid4(),
@@ -41,9 +38,7 @@ class BankAccount(Aggregate):
41
38
  email_address: str
42
39
 
43
40
  def append_transaction(self, amount: Decimal) -> None:
44
- """
45
- Appends given amount as transaction on account.
46
- """
41
+ """Appends given amount as transaction on account."""
47
42
  self.check_account_is_not_closed()
48
43
  self.check_has_sufficient_funds(amount)
49
44
  self.trigger_event(
@@ -59,24 +54,20 @@ class BankAccount(Aggregate):
59
54
  if self.balance + amount < -self.overdraft_limit:
60
55
  raise InsufficientFundsError({"account_id": self.id})
61
56
 
57
+ @dataclass(frozen=True)
62
58
  class TransactionAppended(AggregateEvent):
63
- """
64
- Domain event for when transaction
59
+ """Domain event for when transaction
65
60
  is appended to bank account.
66
61
  """
67
62
 
68
63
  amount: Decimal
69
64
 
70
- def apply(self, account: BankAccount) -> None:
71
- """
72
- Increments the account balance.
73
- """
74
- account.balance += self.amount
65
+ def apply(self, aggregate: Aggregate) -> None:
66
+ """Increments the account balance."""
67
+ cast("BankAccount", aggregate).balance += self.amount
75
68
 
76
69
  def set_overdraft_limit(self, overdraft_limit: Decimal) -> None:
77
- """
78
- Sets the overdraft limit.
79
- """
70
+ """Sets the overdraft limit."""
80
71
  # Check the limit is not a negative value.
81
72
  assert overdraft_limit >= Decimal("0.00")
82
73
  self.check_account_is_not_closed()
@@ -86,38 +77,29 @@ class BankAccount(Aggregate):
86
77
  )
87
78
 
88
79
  class OverdraftLimitSet(AggregateEvent):
89
- """
90
- Domain event for when overdraft
80
+ """Domain event for when overdraft
91
81
  limit is set.
92
82
  """
93
83
 
94
84
  overdraft_limit: Decimal
95
85
 
96
- def apply(self, account: BankAccount):
97
- account.overdraft_limit = self.overdraft_limit
86
+ def apply(self, aggregate: Aggregate) -> None:
87
+ cast("BankAccount", aggregate).overdraft_limit = self.overdraft_limit
98
88
 
99
89
  def close(self) -> None:
100
- """
101
- Closes the bank account.
102
- """
90
+ """Closes the bank account."""
103
91
  self.trigger_event(self.Closed)
104
92
 
105
93
  class Closed(AggregateEvent):
106
- """
107
- Domain event for when account is closed.
108
- """
94
+ """Domain event for when account is closed."""
109
95
 
110
- def apply(self, account: BankAccount):
111
- account.is_closed = True
96
+ def apply(self, aggregate: Aggregate) -> None:
97
+ cast("BankAccount", aggregate).is_closed = True
112
98
 
113
99
 
114
100
  class AccountClosedError(Exception):
115
- """
116
- Raised when attempting to operate a closed account.
117
- """
101
+ """Raised when attempting to operate a closed account."""
118
102
 
119
103
 
120
104
  class InsufficientFundsError(Exception):
121
- """
122
- Raised when attempting to go past overdraft limit.
123
- """
105
+ """Raised when attempting to go past overdraft limit."""