A simple order delivery API app using Python, Django, Django Rest Framework
- Order Calculator
- List items
- Add to cart feature
- Save orders to database
- Order Tracking
This Django application is hosted on aws ec2 instance in DEBUG mode and it can be accessed here. It is hosted using Nginx, Supervisor, Gunicorn.
- Clone this repository
git clone https://github.com/ShreehariVaasishta/order_delivery
- Go to the root directory of this project
cd order_delivery
- Install the dependencies using
pip
. Activate virtual environment if you use one.
pip3 install -r requirements.txt
- Create a
.env
file and make sure the following variables are set
DJANGO_SECRET_KEY=
DEBUG=
- Start the django server
./manage.py runserver
OR
python3 manage.py runserver
Now you should be able to access the Django app running locally at port 8000. Additionally you can specifiy the port for the django app to run in local
./manage.py runserver 0.0.0.0:8080
Now the Django app will be accessible at port 8080
Few basic test cases are already included for the existing order calculation API which inherits Django's TestCase
class.
To run those test cases, run the following command
./manage.py test
OR
python3 manage.py test
Test case results will be displayed in the terminal.
- Python
- Django
- Django Rest Framework
- Added type annotations and comments everywhere which improves code readability
- Used DjangoRestFramework's serializers to validate the request body. Which keeps code readable, modularised and also maintainable.
- Used python dictionaries to store distance range and price allotted to the respective distance.
- Moved utility functions to utility folder. This should keep them easily accessible instead of searching the whole file.
- Constants have a dedicated file in the app which might not change frequently.