application.queries.handlers.get_transaction_handler¶
src.application.queries.handlers.get_transaction_handler
¶
GetTransaction query handler.
Handles requests to retrieve a single transaction. Returns DTO (not domain entity) to prevent leaking domain to presentation.
Architecture: - Application layer handler (orchestrates data retrieval) - Returns Result[DTO, str] (explicit error handling) - NO domain events (queries are side-effect free) - Ownership verification: Transaction->Account->ProviderConnection->User
Reference
- docs/architecture/cqrs-pattern.md
- docs/architecture/transaction-domain-model.md
Classes¶
TransactionResult
dataclass
¶
Single transaction result DTO.
Represents a transaction for API response. Money value objects converted to separate amount+currency fields for serialization.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Transaction unique identifier. |
account_id |
UUID
|
Account FK. |
provider_transaction_id |
str
|
Provider's unique ID. |
transaction_type |
str
|
Type as string (e.g., "trade", "transfer"). |
subtype |
str
|
Subtype as string (e.g., "buy", "deposit"). |
status |
str
|
Status as string (e.g., "settled", "pending"). |
amount_value |
Decimal
|
Transaction amount as Decimal. |
amount_currency |
str
|
Amount currency code. |
description |
str
|
Human-readable description. |
asset_type |
str | None
|
Asset type as string (e.g., "equity", "option") or None. |
symbol |
str | None
|
Security ticker (e.g., "AAPL") or None. |
security_name |
str | None
|
Full security name or None. |
quantity |
Decimal | None
|
Share/unit quantity or None. |
unit_price_amount |
Decimal | None
|
Price per share/unit or None. |
unit_price_currency |
str | None
|
Unit price currency or None. |
commission_amount |
Decimal | None
|
Trading commission or None. |
commission_currency |
str | None
|
Commission currency or None. |
transaction_date |
date
|
Date transaction occurred. |
settlement_date |
date | None
|
Date funds/securities settled or None. |
is_trade |
bool
|
Whether transaction is a trade. |
is_transfer |
bool
|
Whether transaction is a transfer. |
is_income |
bool
|
Whether transaction is income. |
is_fee |
bool
|
Whether transaction is a fee. |
is_debit |
bool
|
Whether transaction debits account (negative). |
is_credit |
bool
|
Whether transaction credits account (positive). |
is_settled |
bool
|
Whether transaction has settled. |
created_at |
datetime
|
First sync timestamp. |
updated_at |
datetime
|
Last sync timestamp. |
Source code in src/application/queries/handlers/get_transaction_handler.py
GetTransactionError
¶
GetTransaction-specific errors.
Source code in src/application/queries/handlers/get_transaction_handler.py
GetTransactionHandler
¶
Handler for GetTransaction query.
Retrieves a single transaction by ID with ownership verification. Uses OwnershipVerifier to verify: Transaction->Account->ProviderConnection->User
Dependencies (injected via constructor): - OwnershipVerifier: For transaction retrieval with ownership verification
Source code in src/application/queries/handlers/get_transaction_handler.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
Functions¶
__init__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ownership_verifier
|
OwnershipVerifier
|
Service for ownership verification. |
required |
Source code in src/application/queries/handlers/get_transaction_handler.py
handle
async
¶
Handle GetTransaction query.
Retrieves transaction, verifies ownership via Account->Connection chain, and maps to DTO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
GetTransaction
|
GetTransaction query with transaction and user IDs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Success |
TransactionResult
|
Transaction found and owned by user. |
Failure |
error
|
Transaction not found or not owned by user. |
Source code in src/application/queries/handlers/get_transaction_handler.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |