"""Logic layer for release approval queue.""" from oto import response from product_workflow.constants import release_correction_status from product_workflow.models import ows_lyrics from product_workflow.models import release_approval_queue from product_workflow.models import release_correction def create_release_approval_queue_record(product_id, approval_data): """Create a new record in release approval queue. Args: product_id (str): unique identifier for the product approval_data (dict): dictionary of data for creating an entry Returns: response.Response with result of creating a new record """ approval_data.update({'release_id': int(product_id)}) approval_response = release_approval_queue.create(approval_data) if not approval_response: return approval_response return response.Response(message=approval_response.message, status=201) def get_last_approval(product_id): """Get the last release approval queue record for the given product id. Args: product_id (str): unique identifier for the product Returns: response.Response with result of getting the last approval queue record """ return release_approval_queue.get_last_approval(product_id) def approve_product(product_id): """Approve product by product_id. Fetch last release correction by product_id then pass this details to ows-lyrics to save correction lyrics value. Args: product_id (str): unique identifier of releases. Returns: response.Response with result of applying correction lyrics value. """ release_correction_details = \ release_correction.get_last_release_correction(product_id) if not release_correction_details or \ not release_correction_details.message['items']: return release_correction_details if release_correction_details.message['status'] == \ release_correction_status.SUBMITTED: for correction_details in release_correction_details.message['items']: if correction_details['field_name'] == 'lyrics': ows_lyrics_respone = \ ows_lyrics.apply_track_lyrics(correction_details) if not ows_lyrics_respone: return ows_lyrics_respone return response.Response()