Commit changes 2
Some checks failed
Android Test / validate-and-test (pull_request) Has been cancelled

This commit is contained in:
LavashGms
2025-12-11 20:42:44 +07:00
parent fb2acb3b70
commit de7df58ef1
3 changed files with 12 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import com.example.nto.entity.Booking;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
/**

View File

@@ -10,4 +10,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface PlaceRepository extends JpaRepository<Place, Long> {
Place findById(long placeId);
}

View File

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