Skip to content

10. Build Get All Employees REST API

Ramesh Fadatare edited this page Sep 11, 2022 · 1 revision

EmployeeService

    List<EmployeeDto> getAllEmployees();

EmployeeServiceImpl

    @Override
    public List<EmployeeDto> getAllEmployees() {
        List<Employee> employees = employeeRepository.findAll();
        return employees.stream()
                .map(employee -> EmployeeConverter.mapToEmployeeDto(employee))
                .collect(Collectors.toList());
    }

EmployeeController

    // build get all employees REST API
    @GetMapping
    public ResponseEntity<List<EmployeeDto>> getAllEmployees(){
        List<EmployeeDto> employees = employeeService.getAllEmployees();
        return new ResponseEntity<>(employees, HttpStatus.OK);
    }