We want to build a new service which can handle the viewing, booking and reservation management of tickets for a number of events. The events will be listed at the end of this document, each event has a limited number of tickets available. An event is defined by a name, a description and a date and time.
We want users of this API to be able to perform the following operations:
- View a list of all events, and associated event information such as name, date, and number of tickets available
- Make a reservation for a number of tickets for a given event
- Manage an existing ticket reservation; possible actions are change amount of tickets or cancel the reservation
A reservation for an amount of tickets for an event cannot exceed the amount of tickets available, in such cases a helpful error message and code should be returned.
Same as the above, a modification for an existing reservation to increase the amount of tickets reserved cannot be performed if the amount of tickets available are less than the additional amount requested. In this case a helpful error message and code should be returned.
Any reservations made through the API should update the available stock of tickets to avoid double bookings. For example: if an event has 100 tickets available from the start, and 100 reservations for single tickets are made, no more tickets should be available for this event.
Ticket cancellations should return the reserved tickets to the stock. The API should handle general errors (such as missing input parameters, incorrect format etc) and give helpful error codes to the API requester, for example in case of input errors or incorrect/missing parameters.
- Event list API
- Reservation API
- Reservation update API
- Cancel reservation API
- Make sure constraints are satisfied
- Event create API
- Event fetch API
- Event update API
- Event delete API
- Docker
- PostgreSQL
- Copy the
.env.template
to.env
file and update the env vars accordingly - Start docker containers
-
docker-compose up web
-
- Stop docker containers
-
docker-compose down
-
- Check application logs
-
docker-compose logs web
-
- Create a python file in
models
folder and create a model there. - Make sure that model is used somewhere in the application
- Generate migration file by replacing the
{migrtion-title}
with some meaningful migration title.-
docker-compose run web flask db revision --autogenerate -m "{migration-title}"
-
Make sure curl is installed and docker containers are running
sh ./inital_data.sh
- Events
- Create event
- Successful request:
curl --request POST \ --url http://localhost:5000/events/ \ --header 'Content-Type: application/json' \ --data '{ "name": "Rocket to Mars", "description": "I'\''m nobody'\''s taxi service; I'\''m not gonna be there to catch you every time you feel like jumping out of a spaceship. I'\''m the Doctor, I'\''m worse than everyone'\''s aunt. *catches himself* And that is not how I'\''m introducing myself.", "date": "2047-10-21T09:00:00Z", "availability": 0 }'
- Response (
201
){ "availability": 0, "created_at": "2023-05-17T16:02:57.040846", "updated_at": "2023-05-17T16:02:57.040846", "description": "I'm nobody's taxi service; I'm not gonna be there to catch you every time you feel like jumping out of a spaceship. I'm the Doctor, I'm worse than everyone's aunt. *catches himself* And that is not how I'm introducing myself.", "name": "Rocket to Mars", "date": "2047-10-21T09:00:00+00:00", "id": "4b029817-f723-4695-9281-ec126747cba2" }
- Malformed request:
curl --request POST \ --url http://localhost:5000/events/ \ --header 'Content-Type: application/json' \ --data '{ "name": "Rocket to Mars", "description": "I'\''m nobody'\''s taxi service; I'\''m not gonna be there to catch you every time you feel like jumping out of a spaceship. I'\''m the Doctor, I'\''m worse than everyone'\''s aunt. *catches himself* And that is not how I'\''m introducing myself.", "date": "2047-10-21T09:00:00Z" }'
- Response (
422
)
{ "availability": [ "Missing data for required field." ] }
- Get event
- Successful request:
curl --request GET \ --url http://localhost:5000/events/4b029817-f723-4695-9281-ec126747cba2
- Response (
200
){ "description": "I'm nobody's taxi service; I'm not gonna be there to catch you every time you feel like jumping out of a spaceship. I'm the Doctor, I'm worse than everyone's aunt. *catches himself* And that is not how I'm introducing myself.", "name": "Rocket to Mars", "availability": 0, "date": "2047-10-21T09:00:00+00:00", "id": "4b029817-f723-4695-9281-ec126747cba2", "created_at": "2023-05-17T16:02:57.040846", "updated_at": "2023-05-17T16:02:57.040846" }
- Event does not exist:
curl --request GET \ --url http://localhost:5000/events/4b029817-f723-4695-9281-ec126747cba1
- Response (
422
)
{ "message": "Event with event id: 4b029817-f723-4695-9281-ec126747cba1 doesn't exist." }
- Get all events
- Successful request:
curl --request GET \ --url http://localhost:5000/events/
- Response (
200
):
[ { "description": "I'm nobody's taxi service; I'm not gonna be there to catch you every time you feel like jumping out of a spaceship. I'm the Doctor, I'm worse than everyone's aunt. *catches himself* And that is not how I'm introducing myself.", "name": "Rocket to Mars", "availability": 0, "date": "2047-10-21T09:00:00+00:00", "id": "4b029817-f723-4695-9281-ec126747cba2", "created_at": "2023-05-17T16:02:57.040846", "updated_at": "2023-05-17T16:02:57.040846" } ]
- Update event
- Successful request:
curl --request PATCH \ --url http://localhost:5000/events/4b029817-f723-4695-9281-ec126747cba2 \ --header 'Content-Type: application/json' \ --data '{ "name": "Rocket to Mars!" }'
- Response (
200
):
{ "description": "I'm nobody's taxi service; I'm not gonna be there to catch you every time you feel like jumping out of a spaceship. I'm the Doctor, I'm worse than everyone's aunt. *catches himself* And that is not how I'm introducing myself.", "name": "Rocket to Mars!", "availability": 0, "date": "2047-10-21T09:00:00+00:00", "id": "4b029817-f723-4695-9281-ec126747cba2", "created_at": "2023-05-17T16:02:57.040846", "updated_at": "2023-05-17T16:02:57.040846" }
- Invalid request:
curl --request PATCH \ --url http://localhost:5000/events/4b029817-f723-4695-9281-ec126747cba2 \ --header 'Content-Type: application/json' \ --data '{ "availability": 10 }'
- Response (
422
):
{ "availability": [ "Unknown field." ] }
- Delete event
- Successful request:
curl --request DELETE \ --url http://localhost:5000/events/7eb194b4-1574-4ec4-9627-38d20748bd30
- Response (
204
)
- Event does not exist
- Same as the one in get event
- Reservations
- Create reservation
- Successful request:
curl --request POST \ --url http://localhost:5000/reservations/ \ --header 'Content-Type: application/json' \ --data '{ "event_id": "6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1", "no_of_tickets": 1 }'
- Response (
201
):{ "event_id": "6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1", "updated_at": "2023-05-17T16:36:32.544453", "cancelled": false, "id": "2c526fa4-897d-4fbc-80e9-974bc12c29b0", "no_of_tickets": 1, "created_at": "2023-05-17T16:36:32.544453" }
- Reservation does not exist:
curl --request POST \ --url http://localhost:5000/reservations/ \ --header 'Content-Type: application/json' \ --data '{ "event_id": "7eb194b4-1574-4ec4-9627-38d20748bd30", "no_of_tickets": 1 }'
- Response (
404
){ "message": "Event with event id: 7eb194b4-1574-4ec4-9627-38d20748bd30 doesn't exist." }
- Insufficient tickets request:
curl --request POST \ --url http://localhost:5000/reservations/ \ --header 'Content-Type: application/json' \ --data '{ "event_id": "cbcaf3e2-4872-4b29-a4c9-4ffbe43c0e47", "no_of_tickets": 1 }'
- Response (
400
):{ "error": "Requested number of tickets are not available." }
- Get reservation
- Successful request:
curl --request GET \ --url http://localhost:5000/reservations/
- Response (
200
){ "event_id": "6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1", "updated_at": "2023-05-17T16:36:32.544453", "cancelled": false, "id": "2c526fa4-897d-4fbc-80e9-974bc12c29b0", "no_of_tickets": 1, "created_at": "2023-05-17T16:36:32.544453" }
- Reservation does not exist
curl --request GET \ --url http://localhost:5000/reservations/6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1
- Response (
404
){ "message": "Reservation with reservation id: 6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1 doesn't exist." }
- Get all reservations
- Successful request:
curl --request GET \ --url http://localhost:5000/reservations/
- Response (
200
):[ { "created_at": "2023-05-17T16:36:32.544453", "no_of_tickets": 1, "id": "2c526fa4-897d-4fbc-80e9-974bc12c29b0", "event_id": "6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1", "cancelled": false, "updated_at": "2023-05-17T16:36:32.544453" }, { "created_at": "2023-05-17T16:40:35.280123", "no_of_tickets": 1, "id": "2b771ade-6e86-49e6-8603-c729c5c37709", "event_id": "6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1", "cancelled": false, "updated_at": "2023-05-17T16:40:35.280123" } ]
- Update reservation
- Successful request:
curl --request PATCH \ --url http://localhost:5000/reservations/2b771ade-6e86-49e6-8603-c729c5c37709 \ --header 'Content-Type: application/json' \ --data '{ "no_of_tickets": 198 }'
- Response (
200
){ "created_at": "2023-05-17T16:40:35.280123", "no_of_tickets": 198, "id": "2b771ade-6e86-49e6-8603-c729c5c37709", "event_id": "6c00a5d6-0ed3-4a23-b6e6-d1eb056cfbd1", "cancelled": false, "updated_at": "2023-05-17T16:40:35.280123" }
- Insufficient tickets request
curl --request PATCH \ --url http://localhost:5000/reservations/2b771ade-6e86-49e6-8603-c729c5c37709 \ --header 'Content-Type: application/json' \ --data '{ "no_of_tickets": 202 }'
- Response (
400
):{ "error": "Requested number of tickets are not available." }
- Invalid request
curl --request PATCH \ --url http://localhost:5000/reservations/2b771ade-6e86-49e6-8603-c729c5c37709 \ --header 'Content-Type: application/json' \ --data '{ "cancelled": false }'
- Response (
422
):{ "cancelled": [ "Unknown field." ] }
- Reservation does not exist
curl --request PATCH \ --url http://localhost:5000/reservations/7eb194b4-1574-4ec4-9627-38d20748bd30 \ --header 'Content-Type: application/json' \ --data '{ "no_of_tickets": 1 }'
- Response (
404
):{ "message": "Event with event id: 7eb194b4-1574-4ec4-9627-38d20748bd30 doesn't exist." }
- Cancel reservation
- Successful request
curl --request DELETE \ --url http://localhost:5000/reservations/2b771ade-6e86-49e6-8603-c729c5c37709
- Response (
204
)
- Reservation does not exist
curl --request DELETE \ --url http://localhost:5000/reservations/20f15f85-2b3a-415d-b7c8-fde8faacb7d4
- Response (
404
):{ "message": "Reservation with reservation id: 20f15f85-2b3a-415d-b7c8-fde8faacb7d4 doesn't exist." }
event-ticket-service's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
- Response (
- Cancel reservation
- Reservation does not exist
- Invalid request
- Insufficient tickets request
- Response (
- Update reservation
- Response (
- Get all reservations
- Reservation does not exist
- Response (
- Get reservation
- Insufficient tickets request:
- Reservation does not exist:
- Response (
- Successful request:
- Response (
- Response (
- Response (
- Event does not exist:
- Response (
- Malformed request:
- Response (
- Successful request:
- Create event