"""Interface for the ows-track microservice.""" from oto import response from owsrequest import request import sentry_sdk from product import config from product.constants import service_name def copy_product_tracks( product_id, new_product_id, orchard_user_id, track_list=None): """Copy a product's tracks. Args: product_id (int): The product_id of the product to copy from. new_product_id (int): The product_id of the product to copy to. orchard_user_id (str): Orchard-User-Id from request header. track_list (list): List of track ids that should be copied. """ try: query_params = { 'orchard_user_id': orchard_user_id} copy_product_tracks_response = request.post( service_name.OWS_TRACK, '/product/{}/tracks/copy/{}'.format(product_id, new_product_id), params=query_params, json={'track_list': track_list}) except Exception: sentry_sdk.capture_exception() return response.create_fatal_response( message='Could not connect to ows-track.') return response.Response(status=copy_product_tracks_response.status_code) def create_product_track(fields): """Create a product's track. Args: fields (dict): Track data. """ try: copy_product_tracks_response = request.post( service_name.OWS_TRACK, '/track', json=fields) except Exception: sentry_sdk.capture_exception() return response.create_fatal_response( message='Could not connect to ows-track.') return response.Response(message=copy_product_tracks_response.json()) def update_product_track(track_id, fields): """Update a product's tracks. Args: track_id (int): The track_id of the track. fields (dict): The fields to copy. """ copy_product_tracks_response = request.process( config.SERVICE_NAME, config.ENVIRONMENT, 'patch', service_name.OWS_TRACK, '/track/{}'.format(track_id), json=fields) return response.Response(message=copy_product_tracks_response.json())