Files
NTO-2025-Backend-TeamTask/src/main/java/com/example/nto/controller/EmployeeController.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();
}
}
}