Exemplo n.º 1
0
def update(id):
    #foundBooks = list(filter(lambda t: t['id']== id, books))
    foundBook = bookDAO.findByID(id)
    if not foundBook:
        abort(404)
    #foundBook = foundBooks[0]
    if not request.json:
        abort(400)
    reqJson = request.json
    if 'Price' in reqJson and type(reqJson['Price']) is not int:
        abort(400)

    if 'Title' in reqJson:
        foundBook['Title'] = reqJson['Title']
    if 'Author' in reqJson:
        foundBook['Author'] = reqJson['Author']
    if 'Price' in reqJson:
        foundBook['Price'] = reqJson['Price']

    if 'Sex' in reqJson:
        foundBook['Sex'] = reqJson['Sex']

    values = (foundBook['Title'], foundBook['Author'], foundBook['Price'],
              foundBook['id'], foundBook['Sex'])
    bookDAO.update(values)
    return jsonify(foundBook)
Exemplo n.º 2
0
def update(id):
    foundBook = bookDAO.findByID(id)
    # Pre-DAO code commented out here
    #foundBooks = list(filter(lambda b: b['id']== id, books))
    #if len(foundBooks)==0:
    if not foundBook:
        abort(404)
    #foundBook = foundBooks[0]
    if not request.json:
        abort(400)
    reqJson = request.json
    if 'Price' in reqJson and type(reqJson['Price']) is not int:
        abort(400)

    if 'Title' in reqJson:
        foundBook['Title'] = reqJson['Title']
    if 'Author' in reqJson:
        foundBook['Author'] = reqJson['Author']
    if 'Price' in reqJson:
        foundBook['Price'] = reqJson['Price']
    values = (foundBook['Title'], foundBook['Author'],
              foundBook['Price'], foundBook['id'])
    # write to data
    bookDAO.update(values)
    return jsonify(foundBook)
Exemplo n.º 3
0
def update(id):
    foundBook = bookDAO.findByID(id)
    if not foundBook:
        abort(404)
    
    if not request.json:
        abort(400)
    reqJson = request.json
    if 'Price' in reqJson and type(reqJson['Price']) is not int:
        abort(400)

    if 'Title' in reqJson:
        foundBook['Title'] = reqJson['Title']
    if 'Author' in reqJson:
        foundBook['Author'] = reqJson['Author']
    if 'Price' in reqJson:
        foundBook['Price'] = reqJson['Price']
    values = (foundBook['Title'],foundBook['Author'],foundBook['Price'],foundBook['id'])
    bookDAO.update(values)
    return jsonify(foundBook)