예제 #1
0
def edit_artist(artist_id):
    try:
        artist = load_and_validate_artist_data('edit', artist_id)
        artist.update()
        return get_success_response(artist.format(), 'Artist updated successfully')
    except exc.SQLAlchemyError as err:
        abort(500, err)
예제 #2
0
def get_role(role_id):
    if not role_id:
        abort(400, 'id must not be null or less than 1')
    role = Role.query.get(role_id)
    if not role:
        abort(404, f"role with id: {role_id} not found")
    return get_success_response(role.format())
예제 #3
0
def add_artist():
    try:
        artist = load_and_validate_artist_data('new')
        artist.insert()
        return get_success_response(artist.format(), 'Artist inserted successfully')
    except exc.SQLAlchemyError as err:
        abort(500, err)
예제 #4
0
def delete_role(role_id):
    if not role_id:
        abort(400, 'id must not be null or less than 1')
    role = Role.query.get(role_id)
    if not role:
        abort(404, f"role with id: {role_id} not found")
    role.delete()
    return get_success_response(None, f'role with id: {role_id} deleted successfully')
예제 #5
0
def delete_artist(artist_id):
    artist = Artist.query.get(artist_id)
    if not artist:
        abort(404, f"artist with id: {artist_id} not found")
    artist.delete()
    return get_success_response(
        data=None,
        msg=f"artist with id: {artist_id} deleted successfully"
    )
예제 #6
0
def add_roles():
    try:
        data = json.loads(request.data)
        role = Role()
        if not data:
            abort(400, 'cannot insert empty data')
        role.load(data)
        validation = role.validate()
        if not validation.get('is_valid'):
            abort(400, f'data not valid {validation.get("errors")}')
        role.id = None
        role.insert()
        return get_success_response(role.format(), 'Role added successfully')
    except exc.SQLAlchemyError as err:
        abort(500, err)
예제 #7
0
def index():
    return get_success_response(None, "Alive and working")
예제 #8
0
def get_artist(artist_id):
    artist = Artist.query.get(artist_id)
    return get_success_response(artist.format()) if artist else\
        get_fail_response(404, f"artist with id: {artist_id} not found")
예제 #9
0
def get_artists_names_list():
    artists = [{'id': artist.id, 'name': artist.name}
               for artist in Artist.query.order_by(Artist.name).all()]
    return get_success_response(artists) if artists else\
        get_fail_response(404, 'no data found')
예제 #10
0
def get_all():
    artists = [artist.format()
               for artist in Artist.query.order_by(Artist.name).all()]
    return get_success_response(artists) if artists else\
        get_fail_response(404, 'no data found')
예제 #11
0
def get_roles_list():
    roles = [role.format() for role in Role.query.all()]
    return get_success_response(roles) if roles else get_fail_response("no roles found")