feat(account): query handlers for account list/get/traffic (task 22)
Summary
• Add three async query handlers for accounts: list_accounts, get_account, get_account_traffic
• Implement AccountViewDto read model without password field (type-level security guarantee)
• Support AND-combining optional filters on service_name, account_type, enabled
• Deliberately keep get_account_traffic side-effect-free (upstream refresh lives in command handler per CQRS rule)
Details
- Query handlers: list (with filters), get (by id), traffic (persisted counters only)
- Read model: AccountViewDto + AccountTrafficDto with serde camelCase for frontend
- Test coverage: 16 new tests across 4 files, all passing (1122 tests total, 7 ignored)
- Type safety: Password field intentionally omitted from DTO — enforced by Rust type system, not runtime checks
- Filter semantics: service_name delegates to repo.list_by_service for SQL efficiency, others filter in-memory
Acceptance Criteria
✅ All 3 handlers implemented and async-tested
✅ AccountViewDto never serializes password (compiler enforced)
✅ Filters combine correctly (service + type + enabled = AND)
✅ Tests: 16 new unit tests with InMemoryAccountRepoForQueries mock
✅ Coverage: 98-100% on query handlers
✅ All acceptance criteria from task spec verified
Summary by cubic
Adds account query handlers for list, get, and traffic, wired into QueryBus, with safe account DTOs that include an opaque credential_ref but never a password. Implements Linear task 22 and keeps traffic queries side-effect free.
-
New Features
list_accounts,get_account,get_account_traffichandlers added toQueryBus.AccountViewDtoandAccountTrafficDtouse camelCase, includecredential_ref, and never include a password or raw credential.- Filters (
service_name,account_type,enabled) AND-combine;service_nameis pruned via repolist_by_service, others filter in memory. - Traffic query returns persisted counters only; refresh stays in the
validate_accountcommand.
-
Migration
- When constructing
QueryBus, pass the account repo via.with_account_repo(...).
- When constructing
Summary by CodeRabbit
-
New Features
- Added account management with persistent storage, listing, and AND-combinable filtering (service, type, enabled).
- Added account detail and traffic endpoints showing usage counters and timestamps.
- Added credential import/export bundle support and opaque credential references; raw passwords are not exposed.
-
Documentation
- Updated changelog with the new account-related features and behaviors.