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 public library needs a REST API to manage its book catalog and lending operations. Build it using Spring Boot and Java.
Resources:
{ id, title, author, isbn, totalCopies, availableCopies }{ id, name, email, membershipDate }{ id, bookId, memberId, borrowDate, dueDate, returnDate, status }Endpoints:
GET /api/books -- list all books, support search by title or author query parameterGET /api/books/{id} -- get a single book by IDPOST /api/books -- add a new book (title, author, isbn required; isbn must be unique; totalCopies >= 1)PUT /api/books/{id} -- update book detailsPOST /api/members -- register a new member (name and email required, email must be unique)GET /api/members/{id} -- get member detailsPOST /api/loans -- borrow a book (bookId and memberId required; book must have available copies; member cannot have more than 5 active loans)POST /api/loans/{id}/return -- return a borrowed bookBusiness rules:
Use an in-memory data structure 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.