-
Notifications
You must be signed in to change notification settings - Fork 0
docs: update coding standards #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
652da57
docs: update coding standards to align with seedwork conventions
aseguragonzalez fbb8d03
docs: align coding standards with PHP seedwork and update CLAUDE.md
aseguragonzalez 2184d7f
Potential fix for pull request finding
aseguragonzalez 5fb3105
Potential fix for pull request finding
aseguragonzalez b284632
Potential fix for pull request finding
aseguragonzalez 2824db9
docs: add owner_id to BankAccount example and align domain event fact…
aseguragonzalez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,72 +1,69 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Self | ||
|
|
||
| from bank_account.domain.bank_account_id import BankAccountId | ||
| from bank_account.domain.errors import CurrencyMismatchError, InsufficientFundsError | ||
| from bank_account.domain.events.account_credited import ( | ||
| AccountCredited, | ||
| AccountCreditedPayload, | ||
| ) | ||
| from bank_account.domain.events.account_debited import ( | ||
| AccountDebited, | ||
| AccountDebitedPayload, | ||
| ) | ||
| from bank_account.domain.events.account_opened import AccountOpened, AccountOpenedPayload | ||
| from bank_account.domain.events.account_credited import AccountCredited | ||
| from bank_account.domain.events.account_debited import AccountDebited | ||
| from bank_account.domain.events.account_opened import AccountOpened | ||
| from bank_account.domain.money import Money | ||
| from bank_account.domain.user_id import UserId | ||
|
|
||
| from seedwork.domain.aggregate_root import AggregateRoot | ||
|
|
||
|
|
||
| @dataclass(frozen=True, eq=False, kw_only=True) | ||
| class BankAccount(AggregateRoot[BankAccountId]): | ||
| owner_id: UserId | ||
| balance: Money | ||
|
|
||
| @classmethod | ||
| def reconstitute(cls, id: BankAccountId, balance: Money) -> Self: | ||
| return cls(id=id, balance=balance) | ||
| def reconstitute(cls, id: BankAccountId, owner_id: UserId, balance: Money) -> Self: | ||
| return cls(id=id, owner_id=owner_id, balance=balance) | ||
|
|
||
| @classmethod | ||
| def open(cls, id: BankAccountId, initial_balance: Money) -> Self: | ||
| event = AccountOpened( | ||
| aggregate_id=id, | ||
| payload=AccountOpenedPayload( | ||
| def open(cls, id: BankAccountId, owner_id: UserId, initial_balance: Money) -> Self: | ||
| return cls(id=id, owner_id=owner_id, balance=initial_balance)._record( | ||
| AccountOpened.create( | ||
| initial_balance=initial_balance.amount, | ||
| currency=initial_balance.currency, | ||
| ), | ||
| aggregate_id=str(id), | ||
| ) | ||
| ) | ||
| return cls(id=id, balance=initial_balance, domain_events=(event,)) | ||
|
|
||
| def credit(self, amount: Money) -> Self: | ||
| if amount.currency != self.balance.currency: | ||
| raise CurrencyMismatchError(self.balance.currency, amount.currency) | ||
| new_amount = self.balance.amount + amount.amount | ||
| new_balance = Money(amount=new_amount, currency=self.balance.currency) | ||
| new_balance = Money( | ||
| amount=self.balance.amount + amount.amount, | ||
| currency=self.balance.currency, | ||
| ) | ||
| return self._evolve(balance=new_balance)._record( | ||
| AccountCredited( | ||
| aggregate_id=self.id, | ||
| payload=AccountCreditedPayload( | ||
| amount=amount.amount, | ||
| currency=amount.currency, | ||
| ), | ||
| AccountCredited.create( | ||
| amount=amount.amount, | ||
| currency=amount.currency, | ||
| aggregate_id=str(self.id), | ||
| ) | ||
| ) | ||
|
|
||
| def validate(self) -> None: | ||
| pass | ||
|
|
||
| def debit(self, amount: Money) -> Self: | ||
| if amount.currency != self.balance.currency: | ||
| raise CurrencyMismatchError(self.balance.currency, amount.currency) | ||
| if amount.amount > self.balance.amount: | ||
| raise InsufficientFundsError() | ||
| new_amount = self.balance.amount - amount.amount | ||
| new_balance = Money(amount=new_amount, currency=self.balance.currency) | ||
| new_balance = Money( | ||
| amount=self.balance.amount - amount.amount, | ||
| currency=self.balance.currency, | ||
| ) | ||
| return self._evolve(balance=new_balance)._record( | ||
| AccountDebited( | ||
| aggregate_id=self.id, | ||
| payload=AccountDebitedPayload( | ||
| amount=amount.amount, | ||
| currency=amount.currency, | ||
| ), | ||
| AccountDebited.create( | ||
| amount=amount.amount, | ||
| currency=amount.currency, | ||
| aggregate_id=str(self.id), | ||
| ) | ||
| ) | ||
|
|
||
| def validate(self) -> None: | ||
| pass |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| from typing import NewType | ||
|
|
||
| UserId = NewType("UserId", str) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.