Study project by creating Spring REST service that simulates the work of cinema
Handle HTTP requests in a controller, create services and respond with JSON objects
- creating Spring REST service
- handle GET/POST requests
- process and respond with JSON data
- throw custom exceptions
The service creates a Cinema with a certain number of seats and a cost depending on the location
By GET request /seats returns JSON
{
"total_rows":5,
"total_columns":6,
"available_seats":[
{
"row":1,
"column":1
},
........
{
"row":5,
"column":5
},
{
"row":5,
"column":6
}
]
}
By POST request /purchase you can buy a ticket. The seat determined by the incoming JSON
{
"row": 5,
"column": 7
}
If the purchase went through, JSON is returned
{
"token": "00ae15f2-1ab6-4a02-a01f-07810b42c0ee",
"ticket": {
"row": 5,
"column": 7,
"price": 8
}
}
Where there is information about the place and unique purchase tokens
If the seat is already taken returns 400 code in JSON
{
"error": "The ticket has been already purchased!"
}
If the location is incorrect, then an error is returned.
"error": "The number of a row or a column is out of bounds!"
POST request on /return returns the ticket if token
is specified
{
"token": "e739267a-7031-4eed-a49c-65d8ac11f556"
}
Returns on success
{
"returned_ticket": {
"row": 1,
"column": 2,
"price": 10
}
}
Else
"error": "Wrong token!"
You can also get statistics using a POST request /stats using the URL parameter password
{
"current_income": 0,
"number_of_available_seats": 81,
"number_of_purchased_tickets": 0
}
Incorrect data returns 401 error with text
"error": "The password is wrong!"