Error handling for Spring Boot APIs — @ControllerAdvice, structured error
84
75%
Does it follow best practices?
Impact
99%
1.76xAverage score across 5 eval scenarios
Passed
No known issues
A community center needs a REST API to manage event scheduling and ticket booking. Build it using Spring Boot and Java.
Resources:
{ id, title, description, date, location, capacity, ticketPrice, status }{ id, eventId, attendeeName, attendeeEmail, numberOfTickets, totalPrice, bookingDate, confirmationCode }Endpoints:
GET /api/events -- list events, support filtering by date range (from/to query params) and statusGET /api/events/{id} -- get event details including remaining capacityPOST /api/events -- create an event (title required, date must be in the future, capacity >= 1, ticketPrice >= 0)PUT /api/events/{id} -- update event details (cannot change capacity below current bookings)DELETE /api/events/{id} -- cancel an event (only if status is "draft"; refund logic out of scope)POST /api/events/{id}/bookings -- book tickets for an event:
GET /api/bookings/{confirmationCode} -- look up a booking by confirmation codeDELETE /api/bookings/{confirmationCode} -- cancel a booking (release capacity back to event)Business rules:
Use in-memory storage or H2 embedded database.
Produce a complete Spring Boot project:
src/main/java/com/example/ -- controller, service, model, and repository packagespom.xml or build.gradle -- with dependenciessrc/main/resources/application.properties -- configurationYou may create additional files as needed for a well-structured codebase.