Exemplo n.º 1
0
def show_with_id(id):
    # PART 2
    if request.method == 'GET':
        if db.getById('shows', int(id)) is None:
            return create_response(status=404,
                                   message="No show with this id exists")
        return create_response({"shows": db.get('shows')[int(id) - 1]})
    if request.method == 'DELETE':
        if db.getById('shows', int(id)) is None:
            return create_response(status=404,
                                   message="No show with this id exists")
        db.deleteById('shows', int(id))
        return create_response(message="Show deleted")
    # PART 4
    if request.method == 'PUT':
        if db.getById('shows', int(id)) is None:
            return create_response(status=404,
                                   message="No show with this id exists")
        else:
            # store values recevied in corresponding variables
            data_json = request.get_data()
            data = json.loads(data_json)

            # if name and episodes are not provided, keep orignal values
            if data['name'] == "":
                data['name'] = db.getById('shows', int(id))['name']
            if data['episodes_seen'] == "":
                data['episodes_seen'] = db.getById('shows',
                                                   int(id))['episodes_seen']

            # update show with corresponding ID
            db.updateById('shows', int(id), data)
            # return results
            return create_response({"shows": db.get('shows')[int(id) - 1]},
                                   status=201)
Exemplo n.º 2
0
def delete_show(id):
    if not id.isdigit():  #type safety
        return create_response(status=404,
                               message="No show with this id exists")
    if db.getById('shows', int(id)) is None:
        return create_response(status=404,
                               message="No show with this id exists")
    db.deleteById('shows', int(id))
    return create_response(message="Show deleted")
Exemplo n.º 3
0
def delete_show(id):
    if db.getById('contacts', int(id)) is None:
        return create_response(status=404,
                               message="No contact with this id exists")
    db.deleteById('contacts', int(id))
    return create_response(message="Contact deleted")
Exemplo n.º 4
0
def delete_restaurant(id):
    if db.getById('restaurants', int(id)) is None:
        return create_response(status=404,
                               message="No restaurant with this id exists")
    db.deleteById('restaurants', int(id))
    return create_response(message="Restaurant deleted")
Exemplo n.º 5
0
def delete_contact(id):
    if db.getById('contacts', int(id)) is None:
        return create_response(
            status=404, message='No contact with id "{0}" exists'.format(id))
    db.deleteById('contacts', int(id))
    return create_response(message="Contact deleted")
Exemplo n.º 6
0
def delete_show(id):
    if db.getById("shows", int(id)) is None:
        return create_response(status=404, message="No show with this id exists")
    db.deleteById("shows", int(id))
    return create_response(message="Show deleted")