47 lines
1.6 KiB
Java
47 lines
1.6 KiB
Java
package com.example.nto.controller;
|
|
|
|
import com.example.nto.service.EmployeeService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
/**
|
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
|
* =================================
|
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
*/
|
|
|
|
@RestController
|
|
@RequestMapping("/api/{code}")
|
|
public class EmployeeController {
|
|
|
|
@Autowired
|
|
private EmployeeService employeeService;
|
|
|
|
@GetMapping("/auth")
|
|
public ResponseEntity<Void> auth(@PathVariable String code) {
|
|
try {
|
|
boolean exists = employeeService.existsByCode(code);
|
|
if (!exists) {
|
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
|
}
|
|
return ResponseEntity.ok().build();
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
|
}
|
|
}
|
|
|
|
@GetMapping("/info")
|
|
public ResponseEntity<?> getInfo(@PathVariable String code) {
|
|
try {
|
|
return employeeService.getEmployeeInfo(code)
|
|
.map(ResponseEntity::ok)
|
|
.orElse(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
|
}
|
|
}
|
|
}
|