63 lines
1.8 KiB
Java
63 lines
1.8 KiB
Java
package com.example.nto.controller;
|
|
|
|
import com.example.nto.entity.Employee;
|
|
import com.example.nto.repository.EmployeeRepository;
|
|
import com.example.nto.service.EmployeeService;
|
|
import com.example.nto.service.impl.EmployeeServiceImpl;
|
|
import org.hibernate.resource.beans.container.spi.BeanLifecycleStrategy;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.net.http.HttpResponse;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
|
* =================================
|
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
*/
|
|
@RestController
|
|
@RequestMapping("api")
|
|
public class EmployeeController {
|
|
|
|
private final EmployeeService employeeService;
|
|
|
|
public EmployeeController(EmployeeService employeeService) {
|
|
|
|
this.employeeService = employeeService;
|
|
}
|
|
|
|
@GetMapping("/{code}/auth")
|
|
public HttpStatus Isauth(@PathVariable String code) {
|
|
if (employeeService.isCodeValid(code)) {
|
|
return HttpStatus.OK;
|
|
|
|
} else if (code == null) {
|
|
return
|
|
HttpStatus.BAD_REQUEST;
|
|
|
|
} else {
|
|
return
|
|
HttpStatus.UNAUTHORIZED;
|
|
}
|
|
}
|
|
|
|
@GetMapping("/{code}/info")
|
|
public ResponseEntity<?> getInfo(@PathVariable String code){
|
|
|
|
Optional<Employee> employee = employeeService.getByCode(code);
|
|
|
|
if (employee.isPresent()) {
|
|
return ResponseEntity.ok(employee.get());
|
|
} else {
|
|
return ResponseEntity.notFound().build();
|
|
}
|
|
|
|
}
|
|
}
|