Command¶
Module defining the Command base class for domain commands.
command
¶
Module defining the Command base class for domain commands.
Command
¶
Bases: Message[CommandRawType]
Base class for all domain commands.
Commands represent an intent to do something in the domain.
They are requests that may succeed or fail, and they are handled by command handler.
Commands are named in imperative mood (e.g., CreateOrder, RegisterCustomer,
ProcessPayment).
Example
class CreateOrder(Command):
... def init(
... self,
... customer_id: str,
... items: list,
... metadata: MessageMetadata | None = None
... ):
... super().init(metadata)
... self._customer_id = customer_id
... self._items = items
...
... @property
... def customer_id(self) -> str:
... return self._customer_id
...
... @property
... def items(self) -> list:
... return self._items
...
... @property
... def _payload(self) -> dict[str, Any]:
... return {
... "customer_id": self._customer_id,
... "items": self._items
... }
Source code in src/forging_blocks/domain/messages/command.py
command_id: UUID
property
¶
Get the unique identifier for this command.
Returns:
| Name | Type | Description |
|---|---|---|
UUID |
UUID
|
The unique command identifier (same as message_id) |
issued_at: datetime
property
¶
Get the timestamp when this command was issued.
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
When the command was issued (same as created_at) |