Ejemplo n.º 1
0
def get_all_bookings_restaurant(fromDate=False,
                                toDate=False,
                                restaurant_id=False):

    reservations = db_session.query(Reservation)
    tables = RestaurantService.get_tables(restaurant_id)
    ints = [table["id"] for table in tables]
    current_app.logger.debug("TABLES INTS: {}".format(ints))
    reservations = reservations.filter(Reservation.table_id.in_(ints))

    # Filtering stuff
    if fromDate is not False:
        reservations = reservations.filter(
            Reservation.reservation_date >= datetime.strptime(
                fromDate, "%Y-%m-%dT%H:%M:%SZ"))
    if toDate is not False:
        reservations = reservations.filter(
            Reservation.reservation_end <= datetime.strptime(
                toDate, "%Y-%m-%dT%H:%M:%SZ"))

    reservations = reservations.all()
    if reservations is None:
        return HttpUtils.error_message(404, "No Reservations")

    current_app.logger.debug("reservations len={}".format(len(reservations)))
    for i, reservation in enumerate(reservations):
        reservations[i] = BookingService.replace_with_customer(reservation)

    return BookingService.reservations_to_json(reservations, "customer"), 200
Ejemplo n.º 2
0
    def test_reservation_to_json_ok(self):
        reservation = Utils.insert_reservation()
        reservation2 = Utils.insert_reservation(people_number=4)
        all_reservations = [reservation, reservation2]

        json_array = BookingService.reservations_to_json(all_reservations,
                                                         what="simple")

        assert len(all_reservations) == len(json_array)
Ejemplo n.º 3
0
def get_all_bookings(user_id=False,
                     fromDate=False,
                     toDate=False,
                     restaurant_id=False):

    reservations = db_session.query(Reservation)
    # Filtering stuff
    if user_id is not False:
        current_app.logger.debug(
            "Adding reservation with filter by user id: {}".format(user_id))
        reservations = reservations.filter(Reservation.customer_id == user_id)
    if fromDate is not False:
        current_app.logger.debug(
            "Adding reservation with filter from date: {}".format(fromDate))
        reservations = reservations.filter(
            Reservation.reservation_date >= datetime.strptime(
                fromDate, "%Y-%m-%dT%H:%M:%SZ"))
    if toDate is not False:
        current_app.logger.debug(
            "Adding reservation with filter to date: {}".format(toDate))
        reservations = reservations.filter(
            Reservation.reservation_end <= datetime.strptime(
                toDate, "%Y-%m-%dT%H:%M:%SZ"))
    if restaurant_id is not False:
        current_app.logger.debug(
            "Adding reservation with filter by restaurant id: {}".format(
                restaurant_id))
        tables = RestaurantService.get_tables(restaurant_id)
        ints = [table["id"] for table in tables]
        current_app.logger.debug("TABLES INTS: {}".format(ints))
        reservations = reservations.filter(Reservation.table_id.in_(ints))

    reservations = reservations.all()
    if reservations is None:
        return HttpUtils.error_message(404, "No Reservations")

    current_app.logger.debug("reservations len={}".format(len(reservations)))
    for i, reservation in enumerate(reservations):
        reservations[i] = BookingService.replace_with_restaurant(reservation)
        current_app.logger.debug("adding people")
        listfriends = []
        current_app.logger.debug("added empty list")
        friends = (db_session.query(Friend).filter_by(
            reservation_id=reservation.id).all())
        current_app.logger.debug("Got friends: {}".format(len(friends)))
        for friend in friends:
            listfriends.append(friend.email.strip())
        current_app.logger.debug("Frinds: {}".format(listfriends))
        reservations[i].people = listfriends
    return BookingService.reservations_to_json(reservations), 200