Beispiel #1
0
def update(id):
    foundFilm = filmDAO.findByID(id)
    if not foundFilm:
        abort(404)

    if not request.json:
        abort(400)
    reqJson = request.json
    if 'Year' in reqJson and type(reqJson['Year']) is not int:
        abort(400)
    if 'Budget' in reqJson and type(reqJson['Budget']) is not int:
        abort(400)

    if 'Title' in reqJson:
        foundFilm['Title'] = reqJson['Title']
    if 'Year' in reqJson:
        foundFilm['Year'] = reqJson['Year']
    if 'Budget' in reqJson:
        foundFilm['Budget'] = reqJson['Budget']
    if 'Director' in reqJson:
        foundFilm['Director'] = reqJson['Director']

    values = (foundFilm['Title'], foundFilm['Year'], foundFilm['Budget'],
              foundFilm['Director'], foundFilm['id'])
    filmDAO.update(values)
    return jsonify(foundFilm)
def findID(id):
    #filmCheck = list(filter(lambda f: f['ID']==id, films))
    #if len(filmCheck)==0:
    #    abort(404)
    #return jsonify({}), 204
    #return jsonify(filmCheck[0])
    foundFilm = filmDAO.findByID(id)
    return jsonify(foundFilm)
def update(id):
    foundFilm = filmDAO.findByID(id)
    if not foundFilm:
        abort(404)
    
    if not request.json:
        abort(400)
    reqJson = request.json
    if 'released' in reqJson and type(reqJson['released']) is not int:
        abort(400)

    if 'title' in reqJson:
        foundFilm['title'] = reqJson['title']
    if 'director' in reqJson:
        foundFilm['director'] = reqJson['director']
    if 'released' in reqJson:
        foundFilm['released'] = reqJson['released']
    values = (foundFilm['title'],foundFilm['director'],foundFilm['released'],foundFilm['id'])
    filmDAO.update(values)
    return jsonify(foundFilm)
def updateFilm(id):
    #changeFilm = list(filter(lambda f: f['ID']==id, films))
    changeFilm = filmDAO.findByID(id)
    if not changeFilm:
        abort(404)

    #if (len(changeFilm) ==0):
    #abort(404)
    #changeFilm = changeFilm[0]

    if not request.json:
        abort(400)

    requestJson = request.json
    if 'Title' in requestJson and type(requestJson['Title']) is not str:
        abort(400)
    if 'Rating' in requestJson and type(requestJson['Rating']) is not int:
        abort(400)
    if 'Director' in requestJson and type(requestJson['Director']) is not str:
        abort(400)
    if 'Votes' in requestJson and type(requestJson['Votes']) is not int:
        abort(400)

    if 'Title' in requestJson:
        changeFilm['Title'] = requestJson['Title']

    if 'Rating' in requestJson:
        changeFilm['Rating'] = requestJson['Rating']

    if 'Director' in requestJson:
        changeFilm['Director'] = requestJson['Director']

    if 'Votes' in requestJson:
        changeFilm['Votes'] = requestJson['Votes']

    filmValues = (changeFilm['Title'], changeFilm['Rating'],
                  changeFilm['Director'], changeFilm['Votes'],
                  changeFilm['ID'])
    filmDAO.update(filmValues)
    return jsonify(changeFilm)
Beispiel #5
0
def findID(id):
    foundFilm = filmDAO.findByID(id)
    return jsonify(foundFilm)
Beispiel #6
0
from filmDAO import filmDAO

#create
latestid = filmDAO.create(("Toy Story", 1995, 50000000, "John Lasseter"))
#find by id
result = filmDAO.findByID(latestid)
print(result)

#update
filmDAO.update(('Santaclause the Movie', 1995, latestid))
result = filmDAO.findByID(latestid)
print(result)

# get all
allFilms = filmDAO.getAll()
for film in allFilms:
    print(film)

# delete
filmDAO.delete(latestid)