Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a wallet and transaction management system for the FastAPI backend, adding new entities and endpoints to handle multi-currency wallet operations. The implementation includes support for three currencies (USD, EUR, RUB) with exchange rate conversion and transaction fees.
- Introduces new Wallet and Transaction database models with proper relationships
- Implements wallet management endpoints (create, read, list)
- Implements transaction endpoints with balance validation and currency conversion
- Adds comprehensive test coverage for all new functionality
Reviewed Changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/app/models/db_models.py | Adds Wallet and Transaction models with Currency/TransactionType enums |
| backend/app/crud.py | Implements CRUD operations for wallets and transactions with exchange rates |
| backend/app/api/routes/wallets.py | Wallet management endpoints with user permissions |
| backend/app/api/routes/transactions.py | Transaction endpoints with balance validation |
| backend/app/tests/api/routes/test_wallets.py | Comprehensive wallet endpoint tests |
| backend/app/tests/api/routes/test_transactions.py | Transaction endpoint test coverage |
| backend/app/alembic/versions/f3b2a1c9d8e7_add_wallet_and_transaction_tables.py | Database migration for new tables |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| class WalletCreate(WalletBase): | ||
| """Model for creating a wallet.""" | ||
|
|
||
| pass |
There was a problem hiding this comment.
[nitpick] The WalletCreate class has an empty body with just pass. Consider adding validation or constraints specific to wallet creation, or use ... (Ellipsis) instead of pass for more explicit intent.
| ) | ||
| amount: float = Field(gt=0.0) | ||
| type: TransactionType | ||
| timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) |
There was a problem hiding this comment.
[nitpick] Using a lambda function for default_factory is unnecessary. Use default_factory=datetime.utcnow or default_factory=lambda: datetime.now(timezone.utc) can be simplified to default=None with proper handling in the application layer.
| "wallet", | ||
| sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False), | ||
| sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
| sa.Column("balance", sa.DECIMAL(precision=10, scale=2), nullable=False), |
There was a problem hiding this comment.
The migration script includes created_at and updated_at columns that are not defined in the SQLModel classes. This mismatch between the migration and model definitions will cause issues.
| sa.Column("created_at", sa.DateTime(), nullable=False), | ||
| sa.Column("updated_at", sa.DateTime(), nullable=False), |
There was a problem hiding this comment.
The migration script includes created_at and updated_at columns that are not defined in the SQLModel classes. This mismatch between the migration and model definitions will cause issues.
94ee233 to
54a718c
Compare
Created a backend endpoints which implements following functionality: - Introduced a new entity Wallet and Transaction. - Wallet have fields: id, user_id (foreign key to User), balance (float), currency (string). - Available currencies: USD, EUR, RUB. - Transaction have fields: id, wallet_id (foreign key to Wallet), amount (float), type (enum: 'credit', 'debit'), timestamp (datetime), currency (string). - Implemented endpoint to create a wallet for a user. - Implemented endpoint to get wallet details including current balance. - Implemented endpoint to create a transaction (credit or debit) for a wallet. # Rules for wallet - A user can have three wallets. - Wallet balance should start at 0.0. - Arithmetic operations on balance should be precise up to two decimal places. # Rules for transaction - For 'credit' transactions, the amount should be added to the wallet balance. - For 'debit' transactions, the amount should be subtracted from the wallet balance. - Ensure that the wallet balance cannot go negative. If a debit transaction would cause the balance to go negative, the transaction should be rejected with an appropriate error message. - Transaction between wallets with different currencies must be converted using a fixed exchange rate (you can hardcode some exchange rates for simplicity) and fees should be applied. Duration: 8m26s My own comments: + Created a migration script + Split wallet and transactions endpoints - Wrote a tests, which wasn't asked - Put everything in crud file, I thinks it's not a best idea
54a718c to
32af472
Compare
Implemented backend task
Created a backend endpoints which implements following functionality:
Rules for wallet
Rules for transaction
Duration: 8m26s
My own comments: