"""Logic for ArtistLinks.""" from owsresponse import response from participant.constants import error from participant.models import artist_links as artist_links_model from participant.utils.convert import format_response def get_artist_links(vendor_id, subaccount_id): """Get artist links for vendor/subaccount. Args: vendor_id (int): the vendors id subaccount_id (int): the subaccount id Returns: response.Response: artist links """ return response.Response( format_response(artist_links_model.get_artist_links(vendor_id, subaccount_id)) ) def update_artist_links(vendor_id, subaccount_id, data): """Update artist links for vendor/subaccount. Args: vendor_id (int): the vendors id subaccount_id (int): the subaccount id data (list of dicts) Returns: response.Response: Ok """ ids = [x['id'] for x in data if 'id' in x] artist_links_for_ids = artist_links_model.get_artist_links_by_ids(ids) if subaccount_id > 0: for artist_link in artist_links_for_ids: if artist_link['subaccount_id'] != subaccount_id: return response.create_error_response( error.ERROR_CODE_AUTHORIZATION, message=error.ERROR_CODE_AUTHORIZATION, ) elif vendor_id > 0: for artist_link in artist_links_for_ids: if artist_link['vendor_id'] != vendor_id: return response.create_error_response( error.ERROR_CODE_AUTHORIZATION, message=error.ERROR_CODE_AUTHORIZATION, ) artist_links_model.update_artist_links(data) return response.Response()