diff --git a/src/main/java/com/example/nto/controller/BookingController.java b/src/main/java/com/example/nto/controller/BookingController.java index 7f6bdd9..276d5b2 100644 --- a/src/main/java/com/example/nto/controller/BookingController.java +++ b/src/main/java/com/example/nto/controller/BookingController.java @@ -32,11 +32,11 @@ public class BookingController { @GetMapping("/booking") public ResponseEntity getFree(@PathVariable String code) { if (!isValidCode(code)) { - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.status(400).build(); // Статус 400 } if (employeeRepository.findByCode(code).isEmpty()) { - return ResponseEntity.status(401).body("Unauthorized"); + return ResponseEntity.status(401).build(); // Статус 401 } Map> free = service.getAvailablePlacesForRange(LocalDate.now(), 4); @@ -49,38 +49,29 @@ public class BookingController { .collect(Collectors.toList()) )); - return ResponseEntity.ok(dto); + return ResponseEntity.ok(dto); // Статус 200 } @PostMapping("/book") public ResponseEntity book(@PathVariable String code, @RequestBody BookingRequestDto dto) { if (!isValidCode(code)) { - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.status(400).build(); // Статус 400 } if (employeeRepository.findByCode(code).isEmpty()) { - return ResponseEntity.status(401).body("Unauthorized"); + return ResponseEntity.status(401).build(); // Статус 401 } try { service.createBooking(code, LocalDate.parse(dto.getDate()), dto.getPlaceId()); - return ResponseEntity.status(201).body("Booking created"); + return ResponseEntity.status(201).build(); // Статус 201 для успешного бронирования } catch (IllegalArgumentException ex) { - String msg = ex.getMessage(); - if ("Place not found".equals(msg)) { - return ResponseEntity.status(400).body("Bad request"); - } - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.status(400).build(); // Ошибка для неверных данных (400) } catch (IllegalStateException ex) { - return ResponseEntity.status(409).body("Conflict"); + return ResponseEntity.status(409).build(); // Ошибка, если место уже забронировано (409) } catch (Exception ex) { - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.status(400).build(); // Общая ошибка для других случаев (400) } } - - @ExceptionHandler({org.springframework.http.converter.HttpMessageNotReadableException.class}) - public ResponseEntity handleBadRequest() { - return ResponseEntity.status(400).body("Bad request"); - } } diff --git a/src/main/java/com/example/nto/controller/EmployeeController.java b/src/main/java/com/example/nto/controller/EmployeeController.java index fc14aa1..f12fc2b 100644 --- a/src/main/java/com/example/nto/controller/EmployeeController.java +++ b/src/main/java/com/example/nto/controller/EmployeeController.java @@ -7,7 +7,6 @@ import com.example.nto.entity.Employee; import com.example.nto.repository.EmployeeRepository; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import org.springframework.http.converter.HttpMessageNotReadableException; import java.util.LinkedHashMap; import java.util.Map; @@ -29,26 +28,26 @@ public class EmployeeController { @GetMapping("/auth") public ResponseEntity auth(@PathVariable String code) { if (!isCodeFormatValid(code)) { - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.status(400).build(); // Статус 400 } boolean exists = employeeRepository.findByCode(code).isPresent(); if (!exists) { - return ResponseEntity.status(401).body("Unauthorized"); + return ResponseEntity.status(401).build(); // Статус 401 для несуществующего сотрудника } - return ResponseEntity.ok().build(); + return ResponseEntity.ok().build(); // Статус 200 для успешной авторизации } @GetMapping("/info") public ResponseEntity info(@PathVariable String code) { if (!isCodeFormatValid(code)) { - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.status(400).build(); // Статус 400 } Employee employee = employeeRepository.findByCode(code).orElse(null); if (employee == null) { - return ResponseEntity.status(401).body("Unauthorized"); + return ResponseEntity.status(401).build(); // Статус 401 для несуществующего сотрудника } Map bookingMap = new LinkedHashMap<>(); @@ -65,11 +64,6 @@ public class EmployeeController { bookingMap ); - return ResponseEntity.ok(dto); - } - - @ExceptionHandler({IllegalArgumentException.class, HttpMessageNotReadableException.class}) - public ResponseEntity handleBadRequest() { - return ResponseEntity.status(400).body("Bad request"); + return ResponseEntity.ok(dto); // Статус 200 для успешной обработки } }