|
|
|
@@ -101,20 +101,16 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|
|
|
|
if (!CheckAuthorization(code))
|
|
|
|
|
return new ResponseEntity<>("кода не существует", HttpStatus.UNAUTHORIZED);
|
|
|
|
|
|
|
|
|
|
Map<String, List<Place>> freePlacesMap = GetFreeBookings(code);
|
|
|
|
|
if (!freePlacesMap.containsKey(bookingInfo.date.toString()))
|
|
|
|
|
return new ResponseEntity<>("что-то пошло не так", HttpStatus.BAD_REQUEST);
|
|
|
|
|
List<Place> freePlaces = freePlacesMap.get(bookingInfo.date.toString());
|
|
|
|
|
for (int i = 0; i < freePlaces.size(); i++) {
|
|
|
|
|
if (freePlaces.get(i).getId() == bookingInfo.placeId) {
|
|
|
|
|
bookingRepository.save(Booking.builder()
|
|
|
|
|
.date(bookingInfo.date)
|
|
|
|
|
.place(freePlaces.get(i))
|
|
|
|
|
.employee(employeeRepository.findByCode(code).get())
|
|
|
|
|
.build());
|
|
|
|
|
return new ResponseEntity<>("бронирование успешно создано", HttpStatus.CREATED);
|
|
|
|
|
}
|
|
|
|
|
List<Booking> allBookings = bookingRepository.findAll();
|
|
|
|
|
for (int i = 0; i < allBookings.size(); i++) {
|
|
|
|
|
if (allBookings.get(i).getDate().toString().equals(bookingInfo.date.toString()) && allBookings.get(i).getPlace().getId() == bookingInfo.placeId)
|
|
|
|
|
return new ResponseEntity<>("уже забронировано", HttpStatus.CONFLICT);
|
|
|
|
|
}
|
|
|
|
|
return new ResponseEntity<>("уже забронировано", HttpStatus.CONFLICT);
|
|
|
|
|
bookingRepository.save(Booking.builder()
|
|
|
|
|
.date(bookingInfo.date)
|
|
|
|
|
.place(placeRepository.findById(bookingInfo.placeId))
|
|
|
|
|
.employee(employeeRepository.findByCode(code).get())
|
|
|
|
|
.build());
|
|
|
|
|
return new ResponseEntity<>("бронирование успешно создано", HttpStatus.CREATED);
|
|
|
|
|
}
|
|
|
|
|
}
|