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

@Copilot Copilot AI review requested due to automatic review settings September 15, 2025 17:55
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 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
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.

[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.

Copilot uses AI. Check for mistakes.

)
amount: float = Field(gt=0.0)
type: TransactionType
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
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.

[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.

Copilot uses AI. Check for mistakes.

"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),
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 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.

Copilot uses AI. Check for mistakes.

Comment on lines +35 to +36
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
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 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.

Copilot uses AI. Check for mistakes.

@vodkar vodkar force-pushed the copilot-claude-no-tuning branch from 94ee233 to 54a718c Compare September 16, 2025 05:57
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
@vodkar vodkar force-pushed the copilot-claude-no-tuning branch from 54a718c to 32af472 Compare September 16, 2025 10:40
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