"""Ows-artist related model tier.""" from owsrequest import request from owsresponse import response from participant.constants import error as error_consts from participant.utils.convert import format_response OWS_ARTIST = 'ows-artist' def get_artist_info_by_artist_id(artist_id): """Make request to ows-artist in order to get artist details. Args: artist_id (int): Artist id Returns: response.Response: Response for given artist_id """ artist_response = request.get( OWS_ARTIST, '/artist/{}'.format(artist_id), headers={'Content-Type': 'application/json'}, ) response_body = artist_response.json() if not response_body: return response.create_error_response( code=error_consts.ERROR_CODE_INVALID_ARTIST, message=error_consts.ERROR_MESSAGE_INVALID_ARTIST_ID, status=response.status.NOT_FOUND, ) return response.Response(format_response(response_body)) def update_artist_info_by_artist_id(artist_id, artist_name): """Make request to ows-artist in order to update artist name. Args: artist_id (int): Artist id artist_name (str): Artist name that has to be updated Returns: response.Response: Response for given update """ params = {'name': artist_name} artist_response = request.put( OWS_ARTIST, '/artist/{}'.format(artist_id), json=params ) if artist_response.status_code not in (200, 201): return response.create_error_response( message=artist_response.content.get('message'), status=artist_response.status_code, code=artist_response.content.get('code'), ) return response.Response(artist_response)