This document describes the wallet and transaction functionality implemented as per the task requirements.
id: UUID primary keyuser_id: Foreign key to User (with CASCADE delete)balance: Decimal with 2 decimal places precision (starts at 0.00)currency: Enum (USD, EUR, RUB)
id: UUID primary keywallet_id: Foreign key to Wallet (with CASCADE delete)amount: Decimal with 2 decimal placestype: Enum ('credit', 'debit')timestamp: DateTime with UTC timezonecurrency: Enum (USD, EUR, RUB)
- A user can have maximum 3 wallets
- Wallet balance starts at 0.0
- Arithmetic operations maintain 2 decimal place precision
- Each user can have only one wallet per currency
- Credit transactions add amount to wallet balance
- Debit transactions subtract amount from wallet balance
- Wallet balance cannot go negative (debit transactions are rejected if insufficient balance)
- Currency conversion between different wallet currencies is supported with hardcoded exchange rates
- 2% conversion fee applied for cross-currency transactions
POST /wallets
Content-Type: application/json
{
"currency": "USD"
}Response: WalletPublic object with wallet details
GET /walletsResponse: List of all wallets for the authenticated user
GET /wallets/{wallet_id}Response: Wallet details including current balance
POST /wallets/{wallet_id}/transactions
Content-Type: application/json
{
"amount": 100.50,
"type": "credit",
"currency": "USD"
}Response: Transaction details
GET /wallets/{wallet_id}/transactions?skip=0&limit=100Response: List of transactions for the wallet, ordered by timestamp (newest first)
The following hardcoded exchange rates are used for currency conversion:
- USD to EUR: 0.85
- USD to RUB: 75.00
- EUR to USD: 1.18
- EUR to RUB: 88.24
- RUB to USD: 0.013
- RUB to EUR: 0.011
The API includes proper error handling for:
- Maximum wallet limit exceeded
- Duplicate currency wallets for same user
- Insufficient balance for debit transactions
- Unsupported currency conversions
- Wallet not found or access denied
A database migration has been created to add the new Wallet and Transaction tables with proper foreign key constraints and indexes.
All endpoints require user authentication and only allow access to wallets owned by the authenticated user.