This project implements a REST API for allocating and purchasing tickets. The API ensures that ticket allocations do not drop below zero and that users cannot purchase more tickets than are available.
- Endpoint:
POST /tickets
- Request Body:
{
"name": "Event Name",
"description": "Event Description",
"allocation": 100
}
- Response:
- 201 Created
{
"id": 1,
"name": "Event Name",
"description": "Event Description",
"allocation": 100
}
- 400 Bad Request if the input is invalid or cannot create ticket
{
"detail": "There was a problem processing your request, please try again",
"status": 400,
"title": "Bad Request"
}
- Endpoint:
GET /tickets/{id}
- Response:
- 200 OK on success
{
"id": 1,
"name": "Event Name",
"description": "Event Description",
"allocation": 100
}
- 404 Not Found if the ticket does not exist
{
"detail": "Not found, please try again",
"status": 404,
"title": "Not Found"
}
- Endpoint:
POST /tickets/{id}/purchases
- Request Body:
{
"quantity": 2,
"user_id": "406c1d05-bbb2-4e94-b183-7d208c2692e1"
}
- Response:
- 200 OK on success
- 400 Bad Request if the requested quantity exceeds the available allocation
{
"detail": "There was a problem processing your request, please try again",
"status": 400,
"title": "Bad Request"
}
- Go for API development
- PostgreSQL for data persistence
- GORM as the ORM
- Docker for containerization
Prerequisites
- Go
- Docker
- PostgreSQL
Running the Application
To clone the repository:
git clone https://github.com/zzeyneperdenn/GoWit-BE-Case-Study.git
Build and run the service using Docker Compose:
make up
The API will be available at http://localhost:8080
Testing
To run the tests: make test