This project implements a RESTful API for managing cinema seat purchases and refunds. The API allows users to purchase tickets, get refunds, view available seats, and retrieve statistics about sales. The system uses a SQLite database to store seat information and sales statistics.
- Seat Purchase: Allows users to purchase seats by specifying row and column numbers. Assigns a unique token to each purchased ticket.
- Seat Refund: Allows users to refund purchased seats using the unique token.
- Seat Availability: Provides an endpoint to retrieve information about the available seats in the cinema.
- Sales Statistics: Provides an endpoint to retrieve sales statistics (total seats, available seats, sold seats, and total revenue). This endpoint is protected by a password.
- Error Handling: Implements custom exception handling for various scenarios like already purchased seats, invalid inputs, and database errors. Returns informative error messages in JSON format.
The API exposes several endpoints:
/purchase
: POST request to purchase a seat. Requires a JSON payload containingrow
,column
, andcustomerFirstName
.- Request Example:
{ "row": 2, "column": 3, "customerFirstName": "John" }
- Response Example (Success):
{ "token": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "ticket": { "row": 2, "column": 3, "price": 18, "purchased": true } }
- Request Example:
/return
: POST request to refund a seat. Requires a JSON payload containingtoken
.- Request Example:
{ "token": "a1b2c3d4-e5f6-7890-1234-567890abcdef" }
- Response Example (Success):
{ "ticket": { "row": 2, "column": 3, "price": 18 } }
- Request Example:
/seats
: GET request to retrieve information about all seats.- Response Example (Success):
{ "totalSeats": 50, "availableSeats": 40, "seats": [ // ... array of Seat objects ... ] }
- Response Example (Success):
/stats
: POST request to retrieve sales statistics. Requires a JSON payload containing thepassword
.- Request Example:
{ "password": "secret" }
- Response Example (Success):
{ "totalSeats": 50, "availableSeats": 40, "purchasedSeats": 10, "totalRevenue": 150 }
- Request Example:
- Java: Programming language
- Spring Boot: Framework for building Spring-based applications
- SQLite: Database
- Maven: Build tool
- Jackson: JSON processing library
- slf4j: Logging facade
The database is configured using a SQLite database file located at src/main/resources/database/cinema_api.db
. The default database schema is created upon application startup. The default admin password for /stats
endpoint is "secret". You can change this by modifying the DB_Creator
class. The default room size is 5x5 rows and columns; you can change this as well in DB_Creator
class.
Made with Etchr