in src/lambdas/modular_api_handler/processors/parent_processor.py [0:0]
def patch(self, event: ParentPatch):
_LOG.debug(f'Update parent event: {event}')
# TODO rewrite
optional_attrs = (APPLICATION_ID_ATTR, TYPE_ATTR, DESCRIPTION_ATTR)
if not any([attr in event for attr in optional_attrs]):
_LOG.warning(f'At least one of the following attributes must be '
f'specifies: \'{optional_attrs}\'.')
raise ResponseFactory(HTTPStatus.BAD_REQUEST).message(
f'At least one of the following attributes must be specifies: \'{optional_attrs}\'.'
).exc()
parent_id = event.get(PARENT_ID_ATTR)
_LOG.debug(f'Describing parent by id \'{parent_id}\'')
parent = self.parent_service.get_parent_by_id(
parent_id=parent_id
)
if not parent:
_LOG.warning(f'Parent with id \'{parent_id}\' does not '
f'exist.')
raise ResponseFactory(HTTPStatus.NOT_FOUND).message(
f'Parent with id \'{parent_id}\' does not exist.'
).exc()
app_id = event.get(APPLICATION_ID_ATTR)
parent_type = event.get(TYPE_ATTR)
description = event.get(DESCRIPTION_ATTR)
_LOG.debug('Updating parent')
self.parent_service.update(
parent=parent, application_id=app_id,
parent_type=parent_type, description=description
)
_LOG.debug('Saving updated parent')
self.parent_service.save(parent=parent)
_LOG.debug('Describing parent dto.')
response = self.parent_service.get_dto(parent=parent)
_LOG.debug(f'Response: {response}')
return build_response(content=response)