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 restaurant chain needs a backend API for their online ordering system. Build it using Spring Boot and Java.
Resources:
{ id, name, description, price, category, available }{ id, customerName, customerPhone, items: [{menuItemId, quantity, specialInstructions}], status, total, createdAt }Endpoints:
GET /api/menu -- list all menu items, support filtering by category query parameterGET /api/menu/{id} -- get a single menu itemPOST /api/menu -- add a menu item (name required, price > 0, category must be one of: appetizer, main, dessert, drink)PUT /api/menu/{id} -- update a menu itemDELETE /api/menu/{id} -- remove a menu item (only if not referenced by pending orders)POST /api/orders -- place an order:
GET /api/orders/{id} -- get order detailsPATCH /api/orders/{id}/status -- update order status (valid transitions: pending -> preparing -> ready -> completed, or pending -> cancelled)Business rules:
Seed the menu with 5-8 sample items. Use in-memory storage or H2.
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.