Update src/main/java/com/example/nto/controller/EmployeeController.java
This commit is contained in:
@@ -1,10 +1,37 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
import com.example.nto.service.EmployeeService;
|
||||
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 {
|
||||
|
||||
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