예제 #1
0
def replace_book():
    changed_book = {
        "isbn": request.form['isbn'],
        "title": request.form['title'],
        "author": request.form['author'],
        "quote": request.form['quote']
    }
    if (not validBookObject(changed_book)):
        invalidBookObjectErrorMsg = {
            "error": "Invalid book object",
            "help": "{'title': '1', 'author': '2', 'quote': '3'}"
        }
        response = Response(json.dumps(invalidBookObjectErrorMsg),
                            status=400,
                            mimetype='application/json')
        return response

    Book.replace_book(oldIsbn, changed_book["isbn"], changed_book["title"],
                      changed_book["author"], changed_book["quote"])
    response = Response("Book changed!", status=204)
    replacementCompletedMsg = {
        'success': 'Book replaced successfully:{0}'.format(changed_book)
    }
    response = Response(json.dumps(replacementCompletedMsg),
                        status=200,
                        mimetype='application/json')
    return response
예제 #2
0
파일: app.py 프로젝트: nntrn/books
def replace_book(isbn):
    request_data = request.get_json()
    if validate_book(request_data):
        Book.replace_book(request_data['isbn'], request_data['name'], request_data['price'])
        response = Response("", 204, mimetype='application/json')
        response.headers['Location'] = '/books/' + str(request_data['isbn'])
        return response
    else:
        return Response('Invalid book object. Must include "name", "price", and "isbn"', status=400,
                        mimetype='application/json')
예제 #3
0
파일: app.py 프로젝트: yoann-dev/flask_api
def replace_book(isbn):
    request_data = request.get_json()
    if valid_book_object_put(request_data):
        Book.replace_book(isbn, request_data['name'], request_data['price'])
        return Response(status=204)
    else:
        invalid_error_msg = {'error': "Invalid book passed in request"}
        return Response(response=json.dumps(invalid_error_msg),
                        status=400,
                        mimetype='application/json')
예제 #4
0
def replace_book(isbn):
    request_data = request.get_json()
    if not valid_put_request_data(request_data):
        invalidBookObjectErrorMsg = {
            "error": "Invalid book object passed in request",
            "helpString": "Data passed in similar to this { 'name' : 'bookName' , 'price' : 2.99 }"
        }
        response = Response(json.dumps(invalidBookObjectErrorMsg), status=400, mimetype='application/json')
        return response

    Book.replace_book(isbn, request_data['name'], request_data['price'])
    response = Response('', 201, mimetype='application/json')
    response.headers['Location'] = '/books/' + str(isbn)
    return response
예제 #5
0
def replace_book(isbn):
    request_data = request.get_json()
    if (not valid_put_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

    Book.replace_book(isbn, request_data['name'], request_data['price'])
    response = Response("", status=204, mimetype='application/json')
    return response
예제 #6
0
def replace_book(isbn):
    request_data = request.get_json()
    if (not (validBookObject(request_data))):
        invalidBookObjectErrorMsg = {
            "error":
            "Valid book object passed must be passed in the request",
            "helpString":
            "Data passed in should look similar to this {'name':'bookname','price':1.01}"
        }
        response = Response(json.dumps(invalidBookObjectErrorMsg),
                            status=400,
                            mimetype='application/json')
        return response

    Book.replace_book(isbn, request_data['name'], request_data['price'])
    response = Response("", status=204)
    return response
예제 #7
0
def replace_book(isbn):
    request_data = request.get_json()

    # Invalid object data in request
    if not valid_put_request_data(request_data):
        errorMsg = {
            'error':
            'Valid book object must be passed in the request',
            'helpString':
            'Data passed in similar to this {"name": "bookName", "price": 7.99}'
        }
        response = Response(json.dumps(errorMsg),
                            status=400,
                            mimetype='application/json')
        return response

    Book.replace_book(isbn, request_data['name'], request_data['price'])

    response = Response("", status=204)
    return response