forked from Olympic/NTO-2025-Backend-TeamTask
вторая попытка
This commit is contained in:
@@ -38,9 +38,6 @@ public class BookingController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/info")
|
||||
public ResponseEntity<Map<String, Object>> info(@PathVariable String code) {
|
||||
Optional<Employee> employeeOpt = employeeService.findByCode(code);
|
||||
@@ -52,7 +49,7 @@ public class BookingController {
|
||||
response.put("name", employee.getName());
|
||||
response.put("photoUrl", employee.getPhotoUrl());
|
||||
|
||||
Map<String, List<Map<String, Object>>> bookingsMap = new HashMap<>();
|
||||
Map<String, Map<String, Object>> bookingsMap = new HashMap<>();
|
||||
List<Booking> bookingList = bookingService.getBookingsByEmployee(employee);
|
||||
|
||||
for (Booking b : bookingList) {
|
||||
@@ -61,7 +58,7 @@ public class BookingController {
|
||||
bookingData.put("id", b.getId());
|
||||
bookingData.put("place", b.getPlace().getPlace());
|
||||
|
||||
bookingsMap.computeIfAbsent(dateKey, k -> new ArrayList<>()).add(bookingData);
|
||||
bookingsMap.put(dateKey, bookingData);
|
||||
}
|
||||
|
||||
response.put("booking", bookingsMap);
|
||||
@@ -102,7 +99,6 @@ public class BookingController {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/book")
|
||||
public ResponseEntity<Void> book(@PathVariable String code, @RequestBody Map<String, String> body) {
|
||||
Optional<Employee> employeeOpt = employeeService.findByCode(code);
|
||||
@@ -111,7 +107,12 @@ public class BookingController {
|
||||
|
||||
try {
|
||||
String dateStr = body.get("date");
|
||||
String placeIdStr = body.get("placeID");
|
||||
|
||||
// поддерживаем все варианты ключей
|
||||
String placeIdStr = body.getOrDefault("placeID",
|
||||
body.getOrDefault("placeId",
|
||||
body.getOrDefault("place", null)));
|
||||
|
||||
if (dateStr == null || placeIdStr == null) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
}
|
||||
@@ -120,12 +121,17 @@ public class BookingController {
|
||||
Long placeId = Long.parseLong(placeIdStr);
|
||||
Place place = placeService.getPlaceById(placeId);
|
||||
|
||||
if (bookingService.getBookingByEmployeeAndDate(employee, date).isPresent()) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).build();
|
||||
}
|
||||
|
||||
if (bookingService.getBookingByDateAndPlace(date, place).isPresent()) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).build();
|
||||
}
|
||||
|
||||
bookingService.createBooking(employee, place, date);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user