internal static async Task <TResult> ExecuteIfValidAsync <T, TResult>(
            this IExecutor <T> executor,
            T request,
            IValidator <T, TResult> validator,
            IVerifier <T, TResult> verifier,
            CancellationToken cancellationToken)
            where TResult : IResult
        {
            var validationResult = validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(validationResult);
            }

            if (verifier is not null)
            {
                var verifierResult = await verifier.VerifyAsync(request);

                if (!verifierResult.IsValid)
                {
                    return(verifierResult);
                }
            }

            await executor.UpdateAsync(request, cancellationToken);

            return(validationResult);
        }
コード例 #2
0
        public async Task <VerificationResponseModel> VerifyIdentityAsync(VerificationRequestModel requestModel)
        {
            var identityVerificationRequest = _mapper.Map <IdentityVerificationRequest>(requestModel);
            var verified = await _verifier.VerifyAsync(identityVerificationRequest);

            var entity = await _kycRepository.GetByKycIdAsync(requestModel.KycId);

            entity.Status = verified ? KycStatus.VerificationPassed : KycStatus.VerificationFailed;
            await _kycRepository.UpdateAsync(entity);

            var responseModel = _mapper.Map <VerificationResponseModel>(identityVerificationRequest);

            responseModel.UserId     = requestModel.UserId;
            responseModel.IsVerified = verified;

            // Send Kafka Message
            var kafkaMessage = new KafkaMessage <string, VerificationResponseModel>
            {
                Key         = Guid.NewGuid().ToString(),
                Value       = responseModel,
                MessageType = nameof(VerificationResponseModel)
            };

            await _verificationProducer.ProduceAsync(kafkaMessage);

            return(responseModel);
        }