API

Employee APIs

  • POST /employees – Create new employee (with optional address and department)

  • GET /employees/{id} – Get employee by ID

  • PUT /employees/{id} – Update employee details

  • DELETE /employees/{id} – Delete employee

  • GET /employees?name=John&department=HR&page=0&size=10&sortBy=hireDate – Get paginated, sorted list of employees with optional filters (name, department, salary range, etc.)

  • GET /employees/by-department/{deptId} – Get employees by department

  • GET /employees/{id}/projects – Get all projects assigned to an employee

  • GET /employees/{id}/salaries – Get all salaries for an employee

  • GET /employees/search – Advanced search using specifications (name, date range, department, etc.)

DTO

EmployeeRequestDTO

This is used for creating or updating an employee.

public class EmployeeRequestDTO {
    private String name;
    private String email;
    private String phone;
    private LocalDate hireDate;
    private Long departmentId;
    private AddressDTO address; // embedded sub-object
}

EmployeeResponseDTO

This is used for returning employee data to the client, including resolved department name, address details, and project names (if needed).

AddressDTO

Used for both request and response to nest address within employee DTOs.

Controller

Repository

Specification Class

Mapper Interface

We can use MapStruct or manual mapping. Example using MapStruct:

Service Interface

Service Implementation

Department APIs

  • POST /departments – Create a new department

  • GET /departments – List all departments

  • GET /departments/{id} – Get department details

  • PUT /departments/{id} – Update department

  • DELETE /departments/{id} – Delete department

Controller

Service Interface

Service Implementation

Repository

DTO

DepartmentRequestDTO

DepartmentResponseDTO

Error Handling

Mapper Interface

Address APIs

  • POST /addresses – Add address

  • PUT /addresses/{id} – Update address

  • GET /addresses/{id} – Get address details

Controller

Service Interface

Service Implementation

Mapper Interface

MapStruct will auto-generate the implementation AddressMapperImpl.

Repository

DTO

AddressRequestDTO.java

AddressResponseDTO.java

Project APIs

  • POST /projects – Create new project

  • GET /projects?client=Google&budgetMin=100000 – List all projects with filter

  • GET /projects/{id} – Get project by ID

  • PUT /projects/{id} – Update project details

  • DELETE /projects/{id} – Delete project

Controller

Service Interface

Service Implementation

Repository

Mapper Interface

DTO

ProjectRequestDTO.java

ProjectResponseDTO.java

Specifications

Relationship APIs

  • POST /employees/{empId}/assign-project/{projId} – Assign a project to an employee

  • DELETE /employees/{empId}/remove-project/{projId} – Remove project assignment

Controller

Service Interface

Service Implementation

Salary APIs

  • POST /salaries – Add new salary record for employee

  • GET /salaries/employee/{empId} – Get all salaries for an employee

  • GET /salaries?month=2024-02&status=PAID&employeeId=4 – Get salaries with pagination, filters (month/year/status/employeeId)

  • PUT /salaries/{id} – Update salary

  • DELETE /salaries/{id} – Delete salary

Controller

Service Interface

Service Implementation

Repository

MapStruct Mapper Interface

DTO

Specification for Filtering

Payment History APIs

  • POST /payments – Add new payment history entry

  • GET /payments/salary/{salaryId} – Get all payments for a salary

  • GET /payments – Paginated list with filters (date range, payment mode, etc.)

Controller

Service Interface

Service Implementation

Repository

MapStruct Mapper Interface

DTO

PaymentHistoryRequestDTO.java

PaymentHistoryResponseDTO.java

Specifications

Dashboard & Reports

  • GET /dashboard/summary – Show employee counts, department-wise summary, salary spend etc.

  • GET /reports/salary-summary?year=2024 – Salary paid per employee/month

  • GET /reports/department-overview – Number of employees, active projects, total salary expense per department

1. GET /dashboard/summary

Controller

Service Interface

Service Implementation

DTO

Custom Query in Repository

2. GET /reports/salary-summary?year=2024

Controller

Service Interface

Service Implementation

DTO

Repository

3. GET /reports/department-overview

Controller

Service Interface

Service Implementation

DTO

Repository

Last updated