Beispiel #1
0
def view_orders():
    db = g.restaurant_name
    status, missing_field = validate_body(request.args, ['phone'])
    if not status:
        return error_response(f'{missing_field} is missing from query params')
    try:
        status, res = view_individual_order(request.args, db)
        if not status:
            return error_response(str(res))
        return response(True, 'Your Orders', res)
    except Exception as err:
        return error_response(str(err))
Beispiel #2
0
def update():
    db = g.restaurant_name
    body = request.get_json()
    status, missing_field = validate_body(body, ['id'])
    if not status:
        return error_response(f'{missing_field} is required')
    try:
        status, data = update_food(body, db)
        if not status:
            return error_response(str(data))
        return response(True, 'Food updated successfully', None)
    except Exception as err:
        return error_response(str(err))
Beispiel #3
0
def order():
    db = g.restaurant_name
    body = request.get_json()
    status, missing_field = validate_body(body, ['phone', 'food_id'])
    if not status:
        return error_response(f'{missing_field} is required')
    try:
        status, res = create_order(body, db)
        if not status:
            return error_response(str(res))
        return response(True, 'Order created successfully', None)
    except Exception as err:
        return error_response(str(err))
Beispiel #4
0
def cancel():
    body = request.get_json()
    db = g.restaurant_name
    status, missing_field = validate_body(body, ['phone'])
    if not status:
        return error_response(f'{missing_field} is required')
    try:
        status, res = cancel_orders(body, db)
        if not status:
            return error_response(str(res))
        return response(True, 'Orders canceled successfully', None)
    except Exception as err:
        return error_response(str(err))
Beispiel #5
0
def deliver():
    body = request.get_json()
    db = g.restaurant_name
    status, missing_field = validate_body(body, ['phone'])
    if not status:
        return error_response(f'{missing_field} is required')
    try:
        status, res = deliver_orders(body, db)
        if not status:
            return error_response(str(res))
        return response(True, 'Orders status updated', None)
    except Exception as err:
        return error_response(str(err))
Beispiel #6
0
def create():
    body = request.get_json()
    db = g.restaurant_name
    status, missing_field = validate_body(body,
                                          ['name', 'picture_url', 'price'])
    if not status:
        return error_response(f'{missing_field} is required')
    try:
        status, res = insert_food(body, db)
        if not status:
            return error_response(str(res))
        return response(True, 'Food created successfully', None)
    except Exception as err:
        return error_response(str(err))
Beispiel #7
0
def signin_staff():
    body = request.get_json()
    db = g.restaurant_name
    status, missing_field = validate_body(body, ['username', 'password'])
    if not status:
        return error_response(f'{missing_field} missing')
    try:
        status, data = login_staff(body, db)
        if not status:
            raise Exception(str(data))
        token = encode_jwt({'name': data['name'], 'restaurant': db})
        return response(True, 'Staff login successful', {
            'token': token,
            'restaurant': db
        })
    except Exception as err:
        return error_response(str(err))