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 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); } } }