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)
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())
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)
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')
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" )
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)
def index(): return get_success_response(None, "Alive and working")
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")
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')
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')
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")