Exemplo n.º 1
0
def delete_character(current_user_token,id):
    owner, current_user_token = verify_owner(current_user_token)
    character = Character.query.get(id)
    db.session.delete(character)
    db.session.commit()
    response = character_schema.dump(character)
    return jsonify(response)
Exemplo n.º 2
0
def get_character(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
    character = Character.query.get(id)
    response = character_schema.dump(character)
    return jsonify(response)
Exemplo n.º 3
0
def get_characters(current_user_token):
    try:
        owner, current_user_token = verify_owner(current_user_token)
    except:
        bad_res = verify_owner(current_user_token)
        return bad_res
        
    characters = Character.query.filter_by(user_id = owner.user_id).all()
    response = character_schema.dump(characters)
    return jsonify(response)
Exemplo n.º 4
0
def update_character(current_user_token,id):
    owner, current_user_token = verify_owner(current_user_token)
    character = Character.query.get(id) # GET CHARACTER INSTANCE

    character.current_alias = request.json['current_alias']
    character.real_name = request.json['real_name']
    character.origin = request.json['origin']
    character.universe = request.json['universe']
    character.power = request.json['power']
    character.comics_appeared_in = request.json['comics_appeared_in']

    db.session.commit()
    response = character_schema.dump(character)
    return jsonify(response)
Exemplo n.º 5
0
def create_character(current_user_token):
    print(current_user_token)
    current_alias = request.json['current_alias']
    real_name = request.json['real_name']
    super_power = request.json['super_power']
    affiliation = request.json['affiliation']
    comics_appeared_in = request.json['comics_appeared_in']
    origin_planet = request.json['origin_planet']
    description = request.json['description']

    user_id = current_user_token.token

    character = Character(current_alias,real_name,super_power, affiliation, comics_appeared_in, origin_planet, description, user_id = user_id)

    db.session.add(character)
    db.session.commit()

    response = character_schema.dump(character)
    return jsonify(response)
Exemplo n.º 6
0
def create_character(current_user_token):
    print(current_user_token)
    current_alias = request.json['current_alias']
    real_name = request.json['real_name']
    origin = request.json['origin']
    universe = request.json['universe']
    power = request.json['power']
    comics_appeared_in = request.json['comics_appeared_in']
    
    user_id = current_user_token.token

    character = Character(current_alias,real_name,origin,universe,power,comics_appeared_in, 
        user_id = user_id)

    db.session.add(character)
    db.session.commit()

    response = character_schema.dump(character)
    return jsonify(response)
Exemplo n.º 7
0
def update_character(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

    character = Character.query.get(id) # GET Character INSTANCE
    character.current_alias = request.json['current_alias']
    character.super_power = request.json['super_power']
    character.description = request.json['description']
    character.real_name = request.json['real_name']
    character.affiliation = request.json['affiliation']
    character.comics_appeared_in = request.json['comics_appeared_in']
    character.origin_planet = request.json['origin_planet']

    db.session.commit()

    response = character_schema.dump(character)
    return jsonify(response)