Пример #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 get_restaurant(restaurant):
    return quote_fields({
        Fields.Id: restaurant.id,
        Fields.WorkdayStart: str(restaurant.workday_start),
        Fields.WorkdayEnd: str(restaurant.workday_end),
        Fields.RestaurantName: restaurant.restaurant_name
    })
Пример #3
0
def get_table(table):
    return quote_fields({
        Fields.Id: table.id,
        Fields.SeatCount: table.seat_count,
        Fields.TableNumber: table.table_number,
        Fields.RestaurantId: table.restaurant_id
    })
Пример #4
0
def get_table_bookings(restaurant_identifier, table_number):
    table = DatabaseController.get_table_from_number_and_restaurant(
        table_number, restaurant_identifier)

    if table:
        return quote_fields({
            Fields.Success:
            True,
            Fields.Bookings:
            FINQ(
                table.bookings).map(lambda b: b.id).map(get_booking).to_list()
        })
    else:
        return quote_fields({
            Fields.Success: False,
            Fields.Error: Errors.NoTable
        })
Пример #5
0
def confirm_booking(booking_id):
    if 'code' in request.args:
        err = DatabaseController.confirm_booking(booking_id,
                                                 int(request.args['code']))
        if err:
            return quote_fields({
                Fields.Success: False,
                Fields.Error: str(err)
            })
        else:
            return quote_fields({
                Fields.Success: True,
                Fields.Booking: get_booking(booking_id)
            })

    return quote_fields({
        Fields.Success: False,
        Fields.Error: Errors.NoConfirmationCode
    })
Пример #6
0
def get_booking(booking_id):
    booking = DatabaseController.get_booking(booking_id)
    if booking:
        return quote_fields({
            Fields.Id:
            booking.id,
            Fields.BookingStartDatetime:
            booking.booking_start_datetime.strftime(DATEFORMAT),
            Fields.BookingEndDatetime:
            booking.booking_end_datetime.strftime(DATEFORMAT),
            Fields.TableId:
            booking.table_id,
            Fields.TableNumber:
            booking.table.table_number
        })
    return quote_fields({
        Fields.Id: booking_id,
        Fields.Error: Errors.NoBooking
    })
Пример #7
0
def get_table_with_bookings(table, start: datetime, end: datetime):
    return quote_fields({
        Fields.Id:
        table.id,
        Fields.SeatCount:
        table.seat_count,
        Fields.TableNumber:
        table.table_number,
        Fields.RestaurantId:
        table.restaurant_id,
        Fields.Bookings:
        FINQ(table.bookings).filter(
            datetime_segment_day_intersections(
                start, end)).map(lambda b: b.id).map(get_booking).to_list()
    })
Пример #8
0
def zip_table(t):
    table, bookings = t
    table_json = get_table(table)
    table_json[Fields.Bookings] = bookings.map(lambda b: b.id).map(
        get_booking).to_list()
    return quote_fields(table_json)
Пример #9
0
def zip_restaurant(rt):
    restaurant, tables = rt
    rdict = get_restaurant(restaurant)
    rdict[Fields.Tables] = tables
    return quote_fields(rdict)