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 getEmployeeByCode(@PathVariable String code) { Optional employeeOpt = employeeService.findByCode(code); if (employeeOpt.isPresent()) { return ResponseEntity.ok(employeeOpt.get()); } else { return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } } }