Files
NTO-2025-Backend-TeamTask-1/src/main/java/com/example/nto/controller/EmployeeController.java

38 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.example.nto.controller;
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
}
}