in src/lambdas/r8s_api_handler/processors/algorithm_processor.py [0:0]
def get(self, event):
_LOG.debug(f'Describe algorithm event: {event}')
alg_id = event.get(ID_ATTR)
name = event.get(NAME_ATTR)
user_customer = event.get(PARAM_USER_CUSTOMER)
if alg_id:
_LOG.debug(f'Describing algorithm by id \'{alg_id}\'')
algorithms = [self.algorithm_service.get_by_id(object_id=alg_id)]
elif name:
_LOG.debug(f'Describing algorithm by name \'{name}\'')
algorithms = [self.algorithm_service.get_by_name(name=name)]
else:
_LOG.debug(f'Describing all algorithms')
algorithms = self.algorithm_service.list()
if user_customer != 'admin':
_LOG.debug(f'Filtering algorithms only from customer '
f'\'{user_customer}\'')
algorithms = [alg for alg in algorithms if
alg and alg.customer == user_customer]
algorithms = [i for i in algorithms if i]
if not algorithms:
_LOG.debug(f'No algorithms found matching given query')
return build_response(
code=RESPONSE_RESOURCE_NOT_FOUND_CODE,
content=f'No algorithms found matching given query'
)
_LOG.debug(f'Got {len(algorithms)} algorithms to describe.'
f' Converting to dto')
algs_gto = [algorithm.get_dto() for algorithm in algorithms]
_LOG.debug(f'Response: {algs_gto}')
return build_response(
code=RESPONSE_OK_CODE,
content=algs_gto
)