Skip to content

Instantly share code, notes, and snippets.

@jeroos
Created October 30, 2024 03:11
Show Gist options
  • Save jeroos/2e8e1c2af8974e7240ef68dd7f79d766 to your computer and use it in GitHub Desktop.
Save jeroos/2e8e1c2af8974e7240ef68dd7f79d766 to your computer and use it in GitHub Desktop.

Event Ticket Booking API

Models

  • Event (Id, Name, DateTime, TicketCategories, AvailableTickets)
  • Booking (Id, EventId, CustomerName, Category, Quantity)

API Endpoints

1. GET /api/events

List upcoming events

  • Query parameters:
{
    "startDate": "2024-11-01",
    "endDate": "2024-12-31",
    "category": "Concert",
    "minPrice": 50,
    "maxPrice": 200
}
  • Response:
{
    "events": [
        {
            "id": 1,
            "name": "Rock Concert 2024",
            "datetime": "2024-11-15T19:00:00",
            "venue": "City Arena",
            "categories": [
                {
                    "name": "VIP",
                    "price": 150.00,
                    "availableSeats": 50
                }
            ]
        }
    ]
}

2. POST /api/bookings

Book tickets

  • Request:
{
    "eventId": 1,
    "categoryId": 1,
    "customerName": "David Lee",
    "email": "[email protected]",
    "quantity": 2
}
  • Validation:
    • Sufficient available seats
    • Maximum 6 tickets per booking
    • Valid email format
    • Payment validation

3. DELETE /api/bookings/{id}

Cancel booking

  • Business rules:
    • Cancellation window (48 hours)
    • Refund policy based on time
    • Release seats back to inventory

4. GET /api/events/{id}/statistics

Get event statistics

  • Response:
{
    "eventName": "Rock Concert 2024",
    "totalCapacity": 1000,
    "ticketsSold": 850,
    "revenue": 127500.00,
    "categoryBreakdown": [
        {
            "name": "VIP",
            "soldPercentage": 90,
            "revenue": 67500.00
        }
    ]
}

Requirements

  • Implement seat selection
  • Handle promotional codes
  • Track ticket transfers
  • Generate QR codes for tickets

Error Handling

Implement global exception handling with appropriate status codes:

  • 400: Bad Request (validation errors)
  • 404: Not Found
  • 409: Conflict (business rule violations)
  • 500: Internal Server Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment