Update src/main/java/com/example/nto/controller/EmployeeController.java
This commit is contained in:
@@ -1,10 +1,37 @@
|
|||||||
package com.example.nto.controller;
|
package com.example.nto.controller;
|
||||||
|
|
||||||
/**
|
import com.example.nto.service.EmployeeService;
|
||||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
import lombok.RequiredArgsConstructor;
|
||||||
* =================================
|
import org.springframework.http.HttpStatus;
|
||||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
import org.springframework.http.ResponseEntity;
|
||||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
import org.springframework.web.bind.annotation.*;
|
||||||
*/
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class EmployeeController {
|
public class EmployeeController {
|
||||||
|
|
||||||
|
private final EmployeeService employeeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET api/{code}/auth
|
||||||
|
*
|
||||||
|
* 400 – что-то пошло не так (пустой код и т.п.)
|
||||||
|
* 401 – кода не существует
|
||||||
|
* 200 – код существует
|
||||||
|
*/
|
||||||
|
@GetMapping("/{code}/auth")
|
||||||
|
public ResponseEntity<Void> auth(@PathVariable("code") String code) {
|
||||||
|
if (code == null || code.isBlank()) {
|
||||||
|
return ResponseEntity.badRequest().build(); // 400
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean exists = employeeService.existsByCode(code);
|
||||||
|
if (!exists) {
|
||||||
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); // 401
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok().build(); // 200
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user