I have completed this interesting assignmend given by Workindia. Worked well on each required statement of the assignment.
- Implement JWT Authentication for User Authentication
- API key Authentication for the Admin Site (Add header
X-IRCTC-API-KEY-SECRET
in the All admin API's) - Handles race conditions while booking
- If more than 1 users simultaneously try to book seats, only either one of the users should be able to book (By adding database lock)
- Focused on code quality and vaidation
- Train is running only between source and destination
- Python
- Django
- MySQL
First clone the github repository
git clone https://github.com/nmastepankaj/irctc_booking_system.git
Open the repository folder in any code editor (VS code) or open any terminal.
You need to create virtual environment for the project. If you don't have virtualenv the install it using the below command :-
virtualenv venv
Now, activate the virtual environment using the below command. If you're window user :-
./venv/Scripts/activate
If you're linux user :-
source venv/bin/activate
install all the project requirements
pip install -r requirement.txt
Now, you need to create migrations and migrate all the migrations
python manage.py makemigrations
python manage.py migrate
Create super user for your project
python manage.py createsuperuser
Run your project
python manage.py runserver
Now your application is ready to use. First register a user and login with the provided credentials.
To access the Admin API you need to create token ( using function generate_api_key
present in utils/token.py
) and add to the db AdminSecret
manually.
To access the user API you need to register then login where you get the access token. Then you this token for user api which starts with /api/user/
The app defines following CRUD APIs.
POST /api/public/account/register
POST /api/public/account/login
POST /api/user/booking/book_ticket
GET /api/user/booking/get_trains
GET /api/user/booking/get_booking/{booking_uuid}
POST /api/admin/booking/add_train
POST /api/admin/booking/add_train_schedule
PATCH /api/admin/booking/update_train_schedule/{schedule_id}