コード例 #1
0
def delete_marvel(current_user_token, id):
    marvel = db.session.query(Marvel).filter(Marvel.id == id,
                                             Marvel.owner == current_user_token.token).first()

    db.session.delete(marvel)
    db.session.commit()
    response = marvel_schema.dump(marvel)
    return jsonify(response)
コード例 #2
0
ファイル: routes.py プロジェクト: greenbc/Marvel-API
def get_marvel_char(current_user_token, id):
    try:
        owner, current_user_token = verify_owner(current_user_token)
    except:
        bad_res = verify_owner(current_user_token)
        return bad_res
    marvel_char = Marvel.query.get(id)
    response = marvel_schema.dump(marvel_char)
    return jsonify(response)
コード例 #3
0
ファイル: routes.py プロジェクト: greenbc/Marvel-API
def delete_marvel_char(current_user_token, id):
    try:
        owner, current_user_token = verify_owner(current_user_token)
    except:
        bad_res = verify_owner(current_user_token)
        return bad_res
    marvel_char = Marvel.query.get(id)
    db.session.delete(marvel_char)
    db.session.commit()
    response = marvel_schema.dump(marvel_char)
    return jsonify(response)
コード例 #4
0
def get_marvel(current_user_token, id):
    try:
        owner, current_user_token = verify_owner(current_user_token)
    except:
        bad_res = verify_owner(current_user_token)
        return bad_res
    marvel = Marvel.query.get(id)
    response = marvel_schema.dump(
        marvel
    )  #dump takes all info and shapeshifts into json string so that the web browser can read
    return jsonify(response)
コード例 #5
0
ファイル: routes.py プロジェクト: greenbc/Marvel-API
def update_marvel_chars(current_user_token, id):
    try:
        owner, current_user_token = verify_owner(current_user_token)
    except:
        bad_res = verify_owner(current_user_token)
        return bad_res
    marvel_char = Marvel.query.get(id)

    marvel_char.name = request.json['name']
    marvel_char.description = request.json['description']
    marvel_char.comics_appeared_in = request.json['comics_appeared_in']
    marvel_char.super_power = request.json['super_power']

    db.session.commit()
    response = marvel_schema.dump(marvel_char)
    return jsonify(response)
コード例 #6
0
def create_marvel(current_user_token):
    print(current_user_token)
    name = request.json['name']
    description = request.json['description']
    comics_appeared_in = request.json['comics_appeared_in']
    super_power = request.json['super_power']
    date_created = request.json['date_created']
    character = request.json['character']
    user_id = current_user_token.token

    marvel = Marvel(name, description, comics_appeared_in,
                    super_power, owner=user_id, character=character)

    db.session.add(marvel)
    db.session.commit()

    response = marvel_schema.dump(marvel)
    return jsonify(response)
コード例 #7
0
def update_marvel(current_user_token, id):
    marvel = Marvel.query.get(id)  # Get Marvel Instance

    if marvel is None:
        return jsonify({'error': 'Not found'}), 404

    marvel.name = request.json['name']
    marvel.description = request.json['description']
    marvel.comics_appeared_in = request.json['comics_appeared_in']
    marvel.super_power = request.json['super_power']
    marvel.date_created = datetime.datetime.now()
    # HACK ALERT: The semantics below is more suited to a PATCH request
    # per the RESTful API design patterns

    marvel.character = request.json.get('character') or marvel.character
    marvel.user_id = current_user_token.token

    db.session.commit()
    response = marvel_schema.dump(marvel)
    return jsonify(response)
コード例 #8
0
def _create_marvel(current_user_token):
    try:
        owner, current_user_token = verify_owner(current_user_token)
    except:
        return jsonify({'error': 'Invalid or expired authentication token'}), 403

    # owner, current_user_token = verify_owner(current_user_token) # does not have to be called again - already called on line 206

    # Instead of lines 197-202, consider _recommendation_1() above

    request_body = request.json
    marvel = Marvel(
        name=request_body['name'],
        description=request_body['description'],
        comics_appeared_in=request_body['comics_appeared_in'],
        super_power=request_body['super_power'],
        owner=owner
    )
    db.session.add(marvel)
    db.session.commit()
    response = marvel_schema.dump(marvel)
    return jsonify(response)