"""Logic for ows-track.""" from owsrequest import request from src import config from src.constants import service def update_track(tuid, data, revisions_not_applied): """Update track.""" if not len(data): return response = request.process( config.APPLICATION_NAME, config.ENVIRONMENT, 'PATCH', service.OWS_TRACK, path=f'/track/{tuid}', headers={'Content-Type': 'application/json'}, json=data, ) if response.status_code != 200: error_msg = ( f'update_track failed for tuid {tuid}\n' f'Status code: {response.status_code}\n' f'Error: {response.text}\n' f'Failed to apply revisions to tracks with tuid ' f'{revisions_not_applied}' ) raise Exception(error_msg) return def update_track_duration(tuid, data, revisions_not_applied): """Update track duration.""" if not len(data): return response = request.process( config.APPLICATION_NAME, config.ENVIRONMENT, 'PATCH', service.OWS_TRACK, path=f'/track/{tuid}/duration', headers={'Content-Type': 'application/json'}, json=data, ) if response.status_code != 200: error_msg = ( f'update_track_duration failed for tuid {tuid}\n' f'Status code: {response.status_code}\n' f'Error: {response.text}\n' f'Failed to apply revisions to tracks with tuid ' f'{revisions_not_applied}' ) raise Exception(error_msg) return def get_multiple_tracks(tuids: list): """Get multiple tracks.""" response = request.process( config.APPLICATION_NAME, config.ENVIRONMENT, 'GET', service.OWS_TRACK, path=f"/tracks?tuids={ ','.join(tuids)}", headers={'Content-Type': 'application/json'} ) if response.status_code != 200: error_msg = ( f'get_multiple_tracks failed for tuids {tuids}\n' f'Status code: {response.status_code}\n' f'Error: {response.text}' ) raise Exception(error_msg) return response.json()