Files
NTO-2025-Backend-TeamTask/src/main/java/com/example/nto/controller/EmployeeController.java
ShipovnikAAA 10595aef83
Some checks failed
Android Test / validate-and-test (pull_request) Has been cancelled
first commit
2025-12-11 18:14:14 +08:00

56 lines
2.3 KiB
Java

package com.example.nto.controller;
import com.example.nto.dto.UserInfoResponse;
import com.example.nto.service.BookingService;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.NoSuchElementException;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
* =================================
* МОЖНО: Добавлять методы, аннотации, зависимости
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class EmployeeController {
private final EmployeeService employeeService;
private final BookingService bookingService;
@GetMapping("/{code}/auth")
public ResponseEntity<String> auth(@PathVariable String code) {
try {
if (employeeService.getEmployeeByCode(code).isPresent()) {
return new ResponseEntity<>("данный код существует - можно пользоваться приложением", HttpStatus.OK);
} else {
return new ResponseEntity<>("кода не существует", HttpStatus.UNAUTHORIZED);
}
} catch (Exception e) {
return new ResponseEntity<>("что-то пошло не так", HttpStatus.BAD_REQUEST);
}
}
@GetMapping("/{code}/info")
public ResponseEntity<?> getInfo(@PathVariable String code) {
if (employeeService.getEmployeeByCode(code).isEmpty()) {
return new ResponseEntity<>("кода не существует", HttpStatus.UNAUTHORIZED);
}
try {
UserInfoResponse userInfo = bookingService.getUserInfo(code);
return new ResponseEntity<>(userInfo, HttpStatus.OK);
} catch (NoSuchElementException e) {
return new ResponseEntity<>("что-то пошло не так", HttpStatus.BAD_REQUEST);
}
}
}