示例#1
0
def book_table_at_restaurant(restaurant_identifier, table_number):
    restaurant = DatabaseController.get_restaurant(restaurant_identifier)
    table = DatabaseController.get_table_from_number_and_restaurant(
        table_number, restaurant_identifier)
    book_info = decoder.decode(request.data.decode("utf8"))

    startTime = datetime.strptime(book_info[Fields.BookingStartDatetime.value],
                                  DATEFORMAT)
    endTime = datetime.strptime(book_info[Fields.BookingEndDatetime.value],
                                DATEFORMAT)
    email = book_info[Fields.Email.value]

    booked, result, booking_id = DatabaseController.pre_book_table(
        startTime, endTime, email, table.id)

    if booked:
        MailController.send_confirmation_code(email, result, booking_id,
                                              startTime, endTime, table_number,
                                              restaurant.restaurant_name)
        return quote_fields({
            Fields.Success: True,
            Fields.BookingId: booking_id
        })
    else:
        return quote_fields({Fields.Success: False, Fields.Error: str(result)})
示例#2
0
def search_all_tables():
    start = datetime.strptime(request.args["startDatetime"], DATEFORMAT)
    end = datetime.strptime(request.args["endDatetime"], DATEFORMAT)
    seat_count = int(request.args["seatsCount"])

    return {
        Fields.Restaurants.value:
        DatabaseController.search_all_tables(start, end, seat_count).group_by(
            lambda t: t[0].restaurant_id).map(lambda l: FINQ(l).map(lambda t: (
                t[0].restaurant_id, zip_table(t))).self(extract_key)).
        map(lambda kl: (DatabaseController.get_restaurant(kl[0]), kl[1])).map(
            zip_restaurant).to_list()
    }
示例#3
0
def get_tables_at_restaurant(identifier):
    return FINQ(DatabaseController.get_restaurant(identifier).tables) \
        .map(get_table) \
        .to_dict(lambda d: d[Fields.Id.value], Identity)