A robust RESTful API built with Spring Boot to handle employee management systems. This service manages CRUD operations for employees, provides data validation, maps between Data Transfer Objects (DTOs) and Entities using ModelMapper, and handles application-specific exceptions globally.
- Full CRUD Operations: Create, Read, Update, and Delete employee records.
- Bulk Ingestion: Create multiple employee records in a single API call.
- Data Validation: Built-in request body validation via
jakarta.validation. - Robust Error Handling: Centralized exception mapping returning clear, readable JSON error structures.
- Layered Architecture: Strictly separates the Web layer (Controllers), Business layer (Services), and Data layer (Entities/DTOs).
- Java 17+
- Spring Boot (Spring Web, Spring Data JPA)
- Jakarta Validation
- ModelMapper (Object Mapping)
- Database: Compatible with relational databases (e.g., PostgreSQL, MySQL, H2) via JPA
All endpoints use the base path: /api/employees
| Method | Endpoint | Description | Success Status |
|---|---|---|---|
| POST | /api/employees |
Create a single employee | 201 Created |
| POST | /api/employees/bulk |
Create multiple employees in bulk | 200 OK |
| GET | /api/employees |
Fetch all employees | 200 OK |
| GET | /api/employees/{id} |
Fetch an employee by ID | 200 OK |
| PUT | /api/employees/{id} |
Update an existing employee | 200 OK |
| DELETE | /api/employees/{id} |
Delete an employee by ID | 204 No Content |
When interacting with the API, requests and responses typically resemble the following JSON format:
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@hankarobotics.com",
"salary": 85000.00,
"department": "R&D",
"position": "Robotics Engineer"
}-
Validation Failures (400 Bad Request)
{ "email": "must be a well-formed email address", "firstName": "must not be blank" } -
Resource Not Found (404 Not Found)
{ "error": "Employee with ID 42 not found." } -
Duplicate Resource (400 Bad Request)
{ "error": "An employee with this email already exists." }
The project strictly follows standard Spring Boot layered conventions to separate web concerns, business logic, and database entities:
org.hanka.robotics
│
├── controllers # REST Controllers exposing the API endpoints
├── service # Service interfaces specifying business logic
├── entity # Database JPA entities (mapped to 'employees' table)
├── dto # Data Transfer Objects for decoupled API request/response
├── converter # ModelMapper configurations translating Entity <-> DTO
└── exceptions # Custom domain exceptions and Global Exception Handler
- Java 17 or higher
- Maven 3.6+
- Clone the repository:
git clone [https://github.com/your-username/your-repo-name.git](https://github.com/your-username/your-repo-name.git) cd your-repo-name
2.Run the application:
mvn spring-boot:run