Esempio n. 1
0
def update_book(isbn):
    request_data = request.get_json()
    if 'name' in request_data:
        Book.update_book_name(isbn, request_data['name'])
    if 'price' in request_data:
        Book.update_book_price(isbn, request_data['price'])
    return Response(status=204)
Esempio n. 2
0
def update_book(isbn):
    request_data = request.get_json()
    if ("name" in request_data):
        Book.update_book_name(isbn, request_data['name'])
    if ("price" in request_data):
        Book.update_book_price(isbn, request_data['price'])

    response = Response("", status=204)
    response.headers['Location'] = '/books' + str(isbn)
    return response
Esempio n. 3
0
def update_book(isbn):
    request_data = request.get_json()

    # Do the updates
    if "name" in request_data:
        Book.update_book_name(isbn, request_data['name'])
    if "price" in request_data:
        Book.update_book_price(isbn, request_data['price'])

    response = Response("", status=204)
    response.headers['Location'] = "/books/" + str(isbn)
    return response
Esempio n. 4
0
def update_book(isbn):
    request_data = request.get_json()
    if not valid_patch_request_data(request_data):
        invalidBookObjectErrorMsg = {
            "error": "Invalid book object passed in request"
        }
        response = Response(json.dumps(invalidBookObjectErrorMsg), status=400, mimetype='application/json')
        return response

    if 'name' in request_data:
        Book.update_book_name(isbn, request_data['name'])
    if 'price' in request_data:
        Book.update_book_price(isbn, request_data['price'])

    response = Response('', 201, mimetype='application/json')
    response.headers['Location'] = '/books/' + str(isbn)
    return response
Esempio n. 5
0
def update_book(isbn):
    request_data = request.get_json()
    if (not valid_patch_request_data(request_data)):
        invalidBookObjectErrorMsg = {
            "error":
            "Invalid book object passed in request",
            "helpString":
            "Data passed in similar to this {'name': 'bookname', 'price': 7.99 }"
        }
        response = Response(json.dumps(invalidBookObjectErrorMsg),
                            status=400,
                            mimetype='application/json')
        return response

    if ("name" in request_data):
        Book.update_book_name(isbn, request_data['name'])
    if ("price" in request_data):
        Book.update_book_price(isbn, request_data['price'])

    response = Response("", status=204, mimetype='application/json')
    response.headers['Location'] = "/books/" + str(isbn)
    return response