Skip to content

Conversation

vodkar
Copy link
Owner

@vodkar vodkar commented Sep 16, 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: 7m 45s

My own comments:

  • Logic is distributed between different files again

@Copilot Copilot AI review requested due to automatic review settings September 16, 2025 07:10
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, introducing new database entities, API endpoints, and business logic for multi-currency financial operations.

Key Changes:

  • Added Wallet and Transaction database models with support for USD, EUR, and RUB currencies
  • Implemented wallet creation, transaction processing, and inter-wallet transfers with currency conversion
  • Created RESTful API endpoints for wallet management with proper authentication and validation

Reviewed Changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
backend/app/models/db_models.py Added Wallet and Transaction database models with currency and transaction type enums
backend/app/models/wallet_models.py Created Pydantic models for wallet and transaction API requests/responses
backend/app/crud.py Implemented CRUD operations for wallets and transactions with business logic validation
backend/app/currency_service.py Added currency conversion service with fixed exchange rates and fee calculations
backend/app/api/routes/wallets.py Created wallet management API endpoints with proper error handling
backend/app/alembic/versions/bb3c7f9e2d12_add_wallet_and_transaction_tables.py Database migration script for new wallet and transaction tables
backend/app/models/init.py Updated exports to include new wallet-related models
backend/app/api/main.py Registered wallet router in main API router
backend/app/constants.py Added wallet-related constants

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

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: 7m 45s

My own comments:
- Logic is distributed between different files again
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