A Ticket Booking System API made using Django
(Python-based free and open-source web framework)
You have to design a REST interface for a movie theatre ticket booking system. It should support the following business cases:
- An endpoint to book a ticket using a user’s name, phone number, and timings.
- Maximum 20 tickets can be booked for a particular time.
- An endpoint to update a ticket timing.
- An endpoint to view all the tickets for a particular time.
- An endpoint to delete a particular ticket.
- An endpoint to view the user’s details based on the ticket id.
- Mark a ticket as expired if there is a diff of 8 hours between the ticket timing and current
- Delete all the tickets which are expired automatically.
- Write the tests for all the endpoints.
Endpoint | HTTP Method | CRUD Method | Result |
---|---|---|---|
api/tickets | GET | READ | Get all tickets |
api/tickets/{id} | GET | READ | Get a ticket using ID |
api/tickets?date={date}&time={time} | GET | READ | Get all tickets with specified ID |
api/tickets | POST | CREATE | Book a Ticket |
api/tickets/{id} | PUT | UPDATE | Update a ticket |
api/tickets/{id} | DELETE | DELETE | Delete a ticket |
- Every 5 minutes - Mark ticket as expired if there is a diff of 8 hours between the ticket time and current time
- Every 10 minutes - Deleting all the Expired Tickets Automatically
- Test Cases - Test Driven RESTful API Development
Name | Phone number | Date | Time | Expired |
---|
- An endpoint to view all the Tickets.
GET
/api/tickets
- An endpoint to view the user’s details based on the ticket id.
GET
/api/tickets/{id}
- An endpoint to view all the tickets for a particular time.
There are 3 functionalities for getting the tickets for a specified Timing, which are:
- To view the tickets for a specified Date and Time
GET
/api/tickets?date={date}&time={time}
- To view the tickets for a specified Date
GET
/api/tickets?date={date}
- To view the tickets for a specified Time
GET
/api/tickets?time={time}
- An endpoint to book a ticket using a user’s name, phone number, and timings.
POST
/api/tickets
- An endpoint to update a ticket timing.
PUT
/api/tickets/{id}/
- An endpoint to delete a particular ticket
DELETE
/api/tickets/{id}/
-
Mark a ticket as expired if there is a diff of 8 hours between the ticket timing and current time.
Added a Cron Job to run at the interval of 5 minutes To Mark a Ticket as Expired if the Difference is greater than or equal to 8 hours.
-
Delete all the tickets which are expired.
Added a Cron Job to run at the interval of 10 minutes to Delete all the Expired Tickets.
To understand the working of the Cron Jobs
- Making Ticket Expired
- Deleting Expired Tickets
Watch the below video,
- To run the
test cases
, use the command
python manage.py test
To write some more test cases for the API, head over to the file API/test.py
. It's the file containing all the test cases for the API.
- Run the command
pip install -r requirements.txt
to install all the required dependencies.
- Now run the command
python manage.py runserver
To run the Django Server on your localhost.
NOTE: If the default port is busy, you can run the server on any other port using the command,
python manage.py runserver localhost:{port number}
You can see the data inside the database in the Django Admin Panel.
Just go to the link
localhost:{port number}/admin
and provide the Username and Password Details. (For simplicity I have already created a SuperUser)
Username | Password |
---|---|
test | test@123 |