forked from Olympic/NTO-2025-Backend-TeamTask
31 lines
940 B
Java
31 lines
940 B
Java
package com.example.nto.controller;
|
|
|
|
import com.example.nto.entity.Employee;
|
|
import com.example.nto.service.EmployeeService;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Optional;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/employee")
|
|
public class EmployeeController {
|
|
|
|
private final EmployeeService employeeService;
|
|
|
|
public EmployeeController(EmployeeService employeeService) {
|
|
this.employeeService = employeeService;
|
|
}
|
|
|
|
@GetMapping("/{code}")
|
|
public ResponseEntity<Employee> getEmployeeByCode(@PathVariable String code) {
|
|
Optional<Employee> employeeOpt = employeeService.findByCode(code);
|
|
if (employeeOpt.isPresent()) {
|
|
return ResponseEntity.ok(employeeOpt.get());
|
|
} else {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
|
}
|
|
}
|
|
}
|