-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
428 Domain Service Enhancements (#430)
Changes: 1. `pre` and `post` invariant structures support for Aggregates, Entities, Value Objects and Domain services. 2. Callable classes for Domain Services. 3. Automatic invariant validation around Domain Service method invocation. 4. Rename `clean()` to `_postcheck` Fixes #428
- Loading branch information
Showing
38 changed files
with
1,123 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from protean import Domain, invariant | ||
from protean.exceptions import ValidationError | ||
from protean.fields import Float, String | ||
|
||
domain = Domain(__name__, load_toml=False) | ||
|
||
|
||
@domain.value_object | ||
class Balance: | ||
currency = String(max_length=3, required=True) | ||
amount = Float(required=True) | ||
|
||
@invariant.post | ||
def check_balance_is_positive_if_currency_is_USD(self): | ||
if self.amount < 0 and self.currency == "USD": | ||
raise ValidationError({"balance": ["Balance cannot be negative for USD"]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.