Small web app using Django that handles fund transfers between two accounts. The app supports importing a list of accounts with opening balances, querying these accounts, and transferring funds between any two accounts.
- Account Management: Manage accounts with details like account number, name, and balance.
- Funds Transfer: Transfer funds securely between accounts.
- Transaction History: Track and view all transaction activities.
Visit the Transfer Funds page to enter account details and the amount to transfer.
Go to the View Accounts page to see a list of all accounts and their details.
Navigate to the Transaction History page to review past transactions.
Ensuring reliable and accurate transactions is crucial. Here's how transactions are managed:
transaction.atomic()
makes sure that operations are performed as a single atomic transaction. If any part fails, everything is rolled back to maintain data consistency.
from django.db import transaction
def transfer_funds(from_account, to_account, amount):
with transaction.atomic():
from_account.refresh_from_db()
to_account.refresh_from_db()
if from_account.balance < amount:
raise ValueError("Insufficient funds")
from_account.balance -= amount
to_account.balance += amount
from_account.save()
to_account.save()
Account records are locked during transactions to prevent concurrent modifications. Using refresh_from_db()
locks the record and ensures up-to-date data.
The search feature allows you to filter accounts based on various criteria:
Exact matching is used for fields like account_number
. When you search by account number, the system finds accounts with the exact number you specify.
Non-exact matching is used for fields like account_name
and balance
. For account names, partial matches are allowed (case-insensitive). For balance, you can specify a range of values to filter accounts that fall within this range.
To use the search functionality, visit the View Accounts page where you can input search criteria and view filtered results.
Testing ensures that our application works correctly. We use pytest
to run our tests and measure code coverage. Code coverage indicates how much of the code is exercised by the tests.
Tests are run using the following command:
pytest --cov=accounts --cov-report html
- Python 3.9 or later
- pip (Python package installer)
- virtualenv (optional but recommended)
- Docker (optional for containerized setup)
-
local using venv and Django
git clone <repository-url> cd Account-Transfer-Task python -m venv venv venv\Scripts\activate python manage.py makemigrations python manage.py migrate
-
local using Docker
docker-compose build
docker-compose up