Задания Backend нто

This commit is contained in:
2025-11-29 15:31:17 +03:00
parent a6954c2013
commit d5564b63eb
15 changed files with 385 additions and 119 deletions

View File

@@ -1,10 +1,27 @@
package com.example.nto.controller;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
* =================================
* МОЖНО: Добавлять методы, аннотации, зависимости
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
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);
return employeeOpt.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build());
}
}