Skip to content

Conversation

vodkar
Copy link
Owner

@vodkar vodkar commented Sep 15, 2025

Implemented backend task

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: 5m53s

My own comments:

  • No tests which I didn't ask for
  • Short implementation
  • Migration was added
  • I didn't ask for WALLET_API.md, so it useless
  • Some mess with models directory now

@Copilot Copilot AI review requested due to automatic review settings September 15, 2025 10:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive wallet and transaction management system for the FastAPI application. The implementation includes new database models for wallets and transactions with currency support, business logic for wallet operations, and REST API endpoints for wallet management.

Key changes include:

  • Added Wallet and Transaction database models with proper relationships and constraints
  • Implemented wallet creation with currency support (USD, EUR, RUB) and user limits
  • Added transaction processing with currency conversion and fee calculation
  • Created REST API endpoints for wallet and transaction operations

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
backend/app/models/db_models.py Added Wallet and Transaction database models with enums for Currency and TransactionType
backend/app/models/wallet_models.py Created Pydantic models for wallet and transaction API operations
backend/app/models/init.py Updated imports to include new wallet-related models
backend/app/api/routes/wallets.py Implemented wallet management endpoints with business logic
backend/app/api/main.py Added wallet router to main API router
backend/app/alembic/versions/add_wallet_and_transaction_models.py Database migration for wallet and transaction tables
WALLET_API.md Added API documentation (not requested)
detailed_issues.csv Updated with new code quality issues
code_quality_summary.csv Updated quality metrics summary

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

id: str
user_id: str
balance: Decimal
currency: str
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The currency field is duplicated from the base class. Remove this redundant field declaration since it's already inherited from WalletBase.

Suggested change
currency: str

Copilot uses AI. Check for mistakes.

statement = (
select(Transaction)
.where(Transaction.wallet_id == wallet_id)
.order_by(Transaction.timestamp.desc())
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation indicates list[TransactionPublic] but based on the pattern used in other endpoints, this should return a paginated response object like TransactionsPublic that includes both data and count fields.

Copilot uses AI. Check for mistakes.

class TransactionBase(SQLModel):
"""Base transaction model with shared fields."""

amount: Decimal = Field(decimal_places=2, ge=0)
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constraint ge=0 prevents negative amounts, but for debit transactions, the business logic should handle negative validation rather than the model constraint. This constraint may cause issues when processing legitimate debit amounts.

Suggested change
amount: Decimal = Field(decimal_places=2, ge=0)
amount: Decimal = Field(decimal_places=2)

Copilot uses AI. Check for mistakes.

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: 5m53s

My own comments:
+ No tests which I didn't ask for
+ Short implementation
+ Migration was added
- I didn't ask for WALLET_API.md, so it useless
- Some mess with models directory now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant