Ejemplo n.º 1
0
def artist_list_albums(id):
    #Return a single artist's album IDs
    albums = db.session.query(aaat).filter(aaat.c.artist_id == id)
    artist = Artist.query.get(id)
    artist_list_new = []
    art_scheme = artist_schema.dump(artist)
    for album in albums:
        album_scheme = album_schema.dump(Album.query.get(album.album_id))
        artist_list_new.append((art_scheme, album_scheme))
    return jsonify(artist_list_new)
Ejemplo n.º 2
0
def artist_create():
    artist_fields = artist_schema.load(request.json)

    new_artist = Artist()
    new_artist.name = artist_fields["name"]

    db.session.add(new_artist)
    db.session.commit()

    return jsonify(artist_schema.dump(new_artist))
Ejemplo n.º 3
0
def artist_update(id):
    artist_fields = artist_schema.load(request.json)

    artist = Artist.query.filter_by(id=id).update(artist_fields)

    if not artist:
        return abort(400)

    db.session.commit()

    return jsonify(artist_schema.dump(artist))
Ejemplo n.º 4
0
def artist_delete(id):
    #Delete a artist
    user_id = get_jwt_identity()

    user = User.query.get(user_id)

    if not user:
        return abort(401, description="Invalid user")

    artist = Artist.query.filter_by(id=id, user_id=user.id).first()

    if not artist:
        return abort(400)

    db.session.delete(artist)
    db.session.commit()

    return jsonify(artist_schema.dump(artist))
Ejemplo n.º 5
0
def artist_update(id):
    #Update a artist
    artist_fields = artist_schema.load(request.json)

    user_id = get_jwt_identity()
    user = User.query.get(user_id)

    if not user:
        return abort(401, description="Invalid user")

    artists = Artist.query.filter_by(id=id, user_id=user.id)

    if artists.count() != 1:
        return abort(401, description="Unauthorized to update this artist")

    artists.update(artist_fields)
    db.session.commit()

    return jsonify(artist_schema.dump(artists[0]))
Ejemplo n.º 6
0
def artist_create():
    #Create a new artist
    artist_fields = artist_schema.load(request.json)

    user_id = get_jwt_identity()
    user = User.query.get(user_id)

    if not user:
        return abort(401, description="Invalid user")

    new_artist = Artist()
    new_artist.artist_name = artist_fields["artist_name"]

    user.artists.append(new_artist)

    db.session.add(new_artist)
    db.session.commit()

    return jsonify(artist_schema.dump(new_artist))
Ejemplo n.º 7
0
def artist_retrive(id):
    return jsonify(artist_schema.dump(Artist.query.get(id)))
Ejemplo n.º 8
0
def artist_show(id):
    #Return a single artist
    artist = Artist.query.get(id)
    return jsonify(artist_schema.dump(artist))