Problem statement
Build a REST API for booking guitar lessons that rejects double-booked tutor slots with a 409 Conflict.
Requirements
BookingController
Implement the two REST endpoints. Each endpoint must be reachable at exactly the verb and path listed below.
GET /bookings
- Return 200 OK with every stored booking, each carrying its id, student, tutor, and slot
- Return 200 OK with an empty array when no bookings exist
POST /bookings
- Accept a JSON body with student, tutor, and slot and validate it
- If student is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Student must not be blank"
- If tutor is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Tutor must not be blank"
- If slot is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Slot must not be blank"
- A rejected request must not add a booking
- On a valid body, save the booking and return 201 Created with the created booking, including its generated id; the booking appears in the list afterwards
- When the body names a tutor and slot that an existing booking already holds, the save fails against the database unique constraint; do not search the stored bookings for a duplicate before saving, instead attempt the save and translate the constraint failure raised by the persistence layer into a 409 Conflict with error message: "Tutor is already booked for this slot"
- A conflicting request must not write a second row: the store keeps exactly the original booking, unchanged, no matter which student sent the conflicting request
- The constraint covers exactly the pair tutor and slot: the same tutor at a different slot is accepted, a different tutor at the same slot is accepted, and the same student may appear in any number of bookings
- After a conflict, the store keeps accepting bookings that do not collide
Sample Requests & Responses
Expand to view details on sample requests and responses.
POST /bookings
Request:
{
"student": "Mia Torres",
"tutor": "Santana",
"slot": "MON-09:00"
}
Response (201 Created):
{
"id": 1,
"student": "Mia Torres",
"tutor": "Santana",
"slot": "MON-09:00"
}
POST /bookings
Request:
{
"student": "Liam Chen",
"tutor": "Santana",
"slot": "MON-09:00"
}
Response (409 Conflict):
{
"error": "Tutor is already booked for this slot",
"timestamp": "2026-07-30T10:14:29.344016",
"path": "/bookings"
}
POST /bookings
Request:
{
"student": "Liam Chen",
"tutor": "Santana",
"slot": "TUE-14:00"
}
Response (201 Created):
{
"id": 3,
"student": "Liam Chen",
"tutor": "Santana",
"slot": "TUE-14:00"
}
POST /bookings
Request:
{
"student": "",
"tutor": "Clapton",
"slot": "WED-10:30"
}
Response (400 Bad Request):
{
"error": "Student must not be blank",
"timestamp": "2026-07-30T10:14:29.446771",
"path": "/bookings"
}
GET /bookings
Response (200 OK):
[
{
"id": 1,
"student": "Mia Torres",
"tutor": "Santana",
"slot": "MON-09:00"
},
{
"id": 3,
"student": "Liam Chen",
"tutor": "Santana",
"slot": "TUE-14:00"
}
]
