def create()

in src/lambdas/modular_api_handler/processors/tenant_processor.py [0:0]


    def create(self, event: TenantPost):
        name = event.name
        acc = event.account_id
        if self.tenant_service.get(tenant_name=name):
            _LOG.warning(f'Tenant with name \'{name}\' already exist.')
            raise ResponseFactory(HTTPStatus.CONFLICT).message(
                f'Tenant with name \'{name}\' already exist.'
            ).exc()

        by_acc = next(self.tenant_service.i_get_by_acc(
            acc=acc, limit=1
        ), None)
        if by_acc:
            _LOG.warning(f'Tenant with account id \'{acc}\' already exist.')
            raise ResponseFactory(HTTPStatus.CONFLICT).message(
                f'Tenant with account id \'{acc}\' already exist.'
            ).exc()

        _LOG.debug('Creating tenant')
        tenant = self.tenant_service.create(
            tenant_name=name,
            display_name=event.display_name,
            customer_name=event.customer_id,
            cloud=event.cloud,
            acc=acc,
            is_active=True,
            read_only=event.read_only,
            contacts={
                'primary_contacts': list(event.primary_contacts),
                'secondary_contacts': list(event.secondary_contacts),
                'tenant_manager_contacts': list(event.tenant_manager_contacts),
                'default_owner': event.default_owner
            }
        )
        _LOG.debug('Saving tenant')
        self.tenant_service.save(tenant=tenant)
        return build_response(
            content=self.tenant_service.get_dto(tenant),
            code=HTTPStatus.CREATED
        )