application.queries.handlers.get_provider_handler¶
src.application.queries.handlers.get_provider_handler
¶
GetProviderConnection query handler.
Handles requests to retrieve a single provider connection. 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)
Reference
- docs/architecture/cqrs-pattern.md
Classes¶
ProviderConnectionResult
dataclass
¶
Single provider connection result DTO.
Represents a provider connection for API response. Does NOT include sensitive data (credentials).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Connection unique identifier. |
user_id |
UUID
|
Owning user's ID. |
provider_id |
UUID
|
Provider registry ID. |
provider_slug |
str
|
Provider identifier (e.g., "schwab"). |
alias |
str | None
|
User-defined nickname (if set). |
status |
ConnectionStatus
|
Current connection status. |
is_connected |
bool
|
Whether connection is usable. |
needs_reauthentication |
bool
|
Whether user needs to re-authenticate. |
connected_at |
datetime | None
|
When connection was first established. |
last_sync_at |
datetime | None
|
Last successful sync timestamp. |
created_at |
datetime
|
Record creation timestamp. |
updated_at |
datetime
|
Last modification timestamp. |
Source code in src/application/queries/handlers/get_provider_handler.py
GetProviderConnectionError
¶
GetProviderConnection-specific errors.
Source code in src/application/queries/handlers/get_provider_handler.py
GetProviderConnectionHandler
¶
Handler for GetProviderConnection query.
Retrieves a single provider connection by ID with ownership check. Uses cache-first strategy for performance.
Dependencies (injected via constructor): - ProviderConnectionRepository: For data retrieval - ProviderConnectionCache: For fast lookups
Source code in src/application/queries/handlers/get_provider_handler.py
Functions¶
__init__
¶
__init__(
connection_repo: ProviderConnectionRepository,
connection_cache: ProviderConnectionCache,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_repo
|
ProviderConnectionRepository
|
Provider connection repository. |
required |
connection_cache
|
ProviderConnectionCache
|
Provider connection cache. |
required |
Source code in src/application/queries/handlers/get_provider_handler.py
handle
async
¶
Handle GetProviderConnection query.
Uses cache-first strategy: 1. Try cache 2. Fall back to database 3. Populate cache on miss
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
GetProviderConnection
|
GetProviderConnection query with connection and user IDs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Success |
ProviderConnectionResult
|
Connection found and owned by user. |
Failure |
error
|
Connection not found or not owned by user. |