A straightforward REST API that stores financial transaction records made by each user, summarizing spending, and receivables, and balances of transactions by category.
- By: Samuel Maciel Sampaio
- Email: mailto:[email protected]
- Github: @samukasmk
This installation mode is the most indicated when the goal is to run in production mode. If you want to install without docker, directly in your machine please read the topic: Extra: Working in your local machine (without docker)
Before you can execute the installing commands, please ensure these external requirements are already installed:
To run this app on Docker containers, please execute the commands below:
# clone this repository
git clone [email protected]:samukasmk/django_wallet.git
# access new folder
cd django_wallet
# build and run the apps inside containers
docker-compose up --build -d
Docker compose example:
After docker-compose
has created the new containers you can access them by URL and passing the content type
of: application/json
Example to access by curl
tool:
curl -X GET http://127.0.0.1/transactions
Swagger is a great REST API documentation tool that works with OpenAPI 3 standards.
If you prefer I've configured Swagger in this project.
To access the API documentation you just need to click on the next URL http://127.0.0.1
But don't forget to check if containers are created and running before accessing Swagger URL
Swagger example:
As requested in the test description, I created 4 endpoint variations of /transactions
verb:
- create many transactions in bulk mode:
POST /transactions
- list all existing transactions:
GET /transactions
- summarize transactions by total inflows and outflows per user:
GET /transactions?group_by=type
- summarize transactions grouped by category:
GET /transactions/{user_email}/summary
I also created in addition, 4 more new endpoints variations of /transaction
verb to:
- create a new single transaction record:
POST /transaction
- retrieve a transaction record by reference id:
GET /transaction/{reference}
- update all transaction fields information:
PUT /transaction/{reference}
- update specific transaction fields information:
PATCH /transaction/{reference}
- and deleting it:
DELETE /transaction/{reference}
POST /transactions
Example:
GET /transactions
Example:
GET /transactions?group_by=type
Example:
GET /transactions/{user_email}/summary
Example:
POST /transaction
Example:
GET /transaction/{reference}
Example:
PUT /transaction/{reference}
Example:
PATCH /transaction/{reference}
Example:
DELETE /transaction/{reference}
Example:
Since docker-compose
has built with success the image containers
you can run the unit tests
directly from docker-compose
with the command:
docker-compose run --rm unit-tests
Example:
Note: I covered as much as possible in terms of time, the variants of test scenarios, reaching the coverage level of 100%, but many tests can be improved in terms of performance, simplicity, and even cover unforeseen scenarios by coverage tool because I wrote them as quickly as possible in the time of I had
This installation mode (without Docker) is a very specific implementation for development purposes like debugging this app in your IDE. If you want to run with Docker, please ignore the instructions below returning to the topic of Installation. To run this Django project on your local machine, execute the commands below:
To run this Django project in your local machine, execute the commands below:
# clone this repository
git clone https://github.com/samukasmk/django_wallet.git
# access new folder
cd django_wallet
# create new virtualenv
python3 -m venv ./venv
source ./venv/bin/activate
# install required libraries
pip install -r requirements.txt
# install, configure run your database by yourself (it can be alone in docker) like:
docker-compose up postgres
# set host address, db name, username, and password in the file: (settings.py)
# note: Even if you are just going to use Postgres on docker-compose alone and the Django app running
# in your machine, the current configuration is already working.
# Because I defined docker-compose.yml to expose the Postgres internal port for your localhost:5432
# ---
# vim settings.py
# export the static files
./manage.py collectstatic
# create the database structure (for new databases installations)
./manage.py migrate
# run the webserver in DEBUG mode
DEBUG=TRUE ./manage.py runserver
# you can run unit tests from make commands:
make test
# or your run pytest directly from your IDE like
pytest .