Deployed version - https://zomentum-task.herokuapp.com/
The rest API's are built using
- Python
- Flask and flask_restx
- MongoDb
To set up the project locally, follow the steps below.
- Set up a virtual environment using
virtualenv .venv
and start it usingsource .venv/bin/activate
- Once that is done, use
pip install -r requirements.txt
to install all of the dependencies. - (optional) If you want to use your own local MongoDb instance, you can replace the testing database URI with yours in
config.py
. - (optional) If you are using local MongoDb instance, you have to run for the very first time
initDb.py
usingPython initDb.py
to initialize collections and TTL Indexes for Auto deletions of expired documents. The testing Database already has this step done. - (optional) If you want to use authentications for all of the endpoints, you can set
apiAuth
toTrue
inconfig.py
. Now all of the endpoints will require theX-Auth-Token
in their headers. - Use
flask run
to start a server at port 5000
-
Post method
/api/book-ticket
can be used to Book a ticket. If the Movie for passed show timing doesn't exists, it creates a new Movie in Movies Collection. Before booking the ticket, it checks forticketCount
which cannot exceed 20. -
Put method
api/update-timing
can be used to update the timing of ticket. -
Get method
/api/view-all-tickets
can be used to view all tickets booked for a movie. EithershowTiming
ormovieId
any of these can be used to check all tickets for a particular movie. -
Put method
/api/delete-ticket
can be used to delete a ticket using it'sticketId
-
Get method
/api/user-details
can be used to see details of the user who booked the ticket usingticketId
-
This part is being handled by MongoDb TTL index that sets Time to live for each document. Since mongodb checks for UTC Time, the
expireAfter
time for each documents is set to 2.5 hours (8 - 5.5) since IST is ahead by 5.5 hours. MongoDb automatically checks for expired tickets every 1 minute and deletes the one whoseshowTiming
is more than current time.
Manual Testing can be done using the Swagger UI or Postman. For automated Unit testing, run python test_api.py
.
You can visit https://zomentum-task.herokuapp.com/ in deployed version or http://127.0.0.1:5000/
in locally set up version to see the Swagger UI. The endpoints for the namespace api
are listed under it and the serializer and models are under models
.
To test any api, select it in the swagger UI as shown in the screenshot and click Try it now
. You can see the expected payload under Example value
and Model
.
To test the API and send data, Edit the values after clicking Try it now
and enter the payload data. Once done, click Execute
to do the request as shown in screenshot.
The Response body, header
and Status code
can be seen just below it.
For testing through postman, you can use this link or use the JSON file in Postman Collection
directory.
Sample Payload and response for few endpoints is shown below.
- movies
- tickets
- movies
- _id: Unique Movie ID
- showTiming: Timing of the Movie
- ticketCount: Count of tickets sold for this movie
- tickets
- _id: Unique ticekt ID
- movieId: Unique movie id (Reference to document in
movies
Collection) - showTiming: Timing of the Movie
- userName: Userame of user
- Phone Number: Phone number of user
- ticketCount: Count of tickets purchased by the user