Win
This commit is contained in:
@@ -1,10 +1,58 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class EmployeeController {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
@GetMapping("/{code}/auth")
|
||||
public ResponseEntity<Void> checkAuth(
|
||||
@PathVariable String code,
|
||||
@RequestHeader(value = "Authorization", required = false) String authHeader) {
|
||||
if (authHeader == null || !authHeader.equals("Bearer valid-token")) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
try {
|
||||
employeeService. getEmployeeWithBookings(code);
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
} catch (EmployeeNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/info")
|
||||
public ResponseEntity<?> getEmployeeInfo(@PathVariable String code) {
|
||||
try {
|
||||
Employee response = employeeService.getEmployeeWithBookings(code);
|
||||
return ResponseEntity.ok(response);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.status(400).body(e.getMessage());
|
||||
} catch (EmployeeNotFoundException e) {
|
||||
return ResponseEntity.status(404).body(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user