コード例 #1
0
ファイル: app.py プロジェクト: yoann-dev/flask_api
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)
コード例 #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
コード例 #3
0
ファイル: app.py プロジェクト: zmour/ps-flask-rest-api
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
コード例 #4
0
ファイル: app.py プロジェクト: prazjain/python-flask-rest-api
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
コード例 #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