Example #1
2
  public Long getBookingSlotsLeft(TimeSlot timeSlot, Offer offer, List<Booking> confirmedBookings) {
    checkForBookedCourts(timeSlot, confirmedBookings, true);

    Long bookingSlotsLeft = offer.getMaxConcurrentBookings();
    for (Booking existingBooking : timeSlot.getBookings()) {
      if (existingBooking.getOffer().equals(offer)) {
        bookingSlotsLeft--;
      }
    }
    return bookingSlotsLeft;
  }
Example #2
0
  public void checkForBookedCourts(
      TimeSlot timeSlot, List<Booking> confirmedBookings, Boolean preventOverlapping) {
    LocalTime startTime = timeSlot.getStartTime();
    LocalTime endTime = timeSlot.getEndTime();

    for (Booking booking : confirmedBookings) {

      if (timeSlot.getDate().equals(booking.getBookingDate())) {
        LocalTime bookingStartTime = booking.getBookingTime();
        LocalTime bookingEndTime = bookingStartTime.plusMinutes(booking.getDuration().intValue());
        Boolean addBooking = false;
        if (preventOverlapping) {
          if (startTime.isBefore(bookingEndTime)) {
            if (endTime.isAfter(bookingStartTime)) {
              addBooking = true;
            }
          }
        } else {
          // for displaying allocations
          if (startTime.compareTo(bookingStartTime) >= 0) {
            if (endTime.compareTo(bookingEndTime) <= 0) {
              addBooking = true;
            }
          }
        }
        if (addBooking) {
          Offer offer = booking.getOffer();
          for (Offer timeSlotOffer : timeSlot.getConfig().getOffers()) {
            if (offer.equals(timeSlotOffer)) {
              timeSlot.addBooking(booking);
              break;
            }
          }
        }
      }
    }
  }