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
An HR department needs a REST API to manage their employee directory. Build it using Spring Boot and Java.
Resources:
{ id, name, managerId }{ id, firstName, lastName, email, departmentId, jobTitle, salary, hireDate }Endpoints:
GET /api/departments -- list all departmentsPOST /api/departments -- create a department (name required, must be unique)GET /api/departments/{id} -- get department details including employee countGET /api/departments/{id}/employees -- list employees in a department, support pagination (page, size params)POST /api/employees -- create an employee (firstName, lastName, email required; email must be unique; departmentId must reference an existing department; salary must be positive)GET /api/employees/{id} -- get an employee by IDPUT /api/employees/{id} -- update employee detailsDELETE /api/employees/{id} -- remove an employee (cannot delete a department manager)PATCH /api/employees/{id}/transfer -- transfer an employee to a different department (body: { departmentId })Business rules:
Use H2 embedded database with Spring Data JPA.
Produce a complete Spring Boot project:
src/main/java/com/example/ -- controller, service, model/entity, and repository packagespom.xml or build.gradle -- with dependenciessrc/main/resources/application.properties -- configuration including H2 settingsYou may create additional files as needed for a well-structured codebase.