Exemple #1
0
 public WarrantyService(
     FailureClassification failureClassification,
     IRequestIdGenerator requestIdGenerator,
     ComprehensiveDataWrapper comprehensiveDataWrapper,
     BudgetDataWrapper budgetDataWrapper,
     RequestValidator requestValidator,
     RequestBuilder requestBuilder,
     ExternalPartyWrapper externalPartyWrapper,
     ResponseValidator responseValidator,
     ResponseConverter responseConverter)
 {
     FailureClassification    = failureClassification;
     RequestIdGenerator       = requestIdGenerator;
     ComprehensiveDataWrapper = comprehensiveDataWrapper;
     BudgetDataWrapper        = budgetDataWrapper;
     RequestValidator         = requestValidator;
     RequestBuilder           = requestBuilder;
     ExternalPartyWrapper     = externalPartyWrapper;
     ResponseValidator        = responseValidator;
     ResponseConverter        = responseConverter;
 }
Exemple #2
0
        // success means called Thrid Party, saved raw request and raw response, (and saved warrantyProof), and returns a converted response
        // ---
        // anything here after SaveExternalPartyResponse in BudgetDatabase should be pure (non-deterministic and no side-effect)
        // so that the saved ExternalPartyResponse can be a source of truth
        internal async Task <Result <WarrantyCaseResponse, IFailure> > PerformVerifyAction(
            VerifyWarrantyCaseRequest request,
            WarrantyCaseOperation operation,
            Guid requestId)
        {
            var validateRequestResult = RequestValidator.Validate(request, operation, requestId);

            if (!validateRequestResult.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(validateRequestResult.Failure !));
            }

            var build = RequestBuilder.Build(request, operation, requestId);

            if (!build.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(build.Failure !));
            }
            var warrantyRequest = build.Success !;

            var saveWarrantyRequest = await BudgetDataWrapper.SaveExternalPartyRequest(
                new ExternalPartyRequest(
                    orderId : request.OrderId,
                    request : JsonConvert.SerializeObject(warrantyRequest))
            {
                Operation = operation,
                RequestId = requestId,
            });

            if (!saveWarrantyRequest.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(saveWarrantyRequest.Failure !));
            }

            var call = await ExternalPartyWrapper.Call(warrantyRequest);

            if (!call.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(call.Failure !));
            }
            var rawResponse = call.Success !;

            var saveWarrantyResponse = await BudgetDataWrapper.SaveExternalPartyResponse(
                new ExternalPartyResponse(
                    orderId : request.OrderId,
                    response : JsonConvert.SerializeObject(rawResponse))
            {
                Operation = operation,
                RequestId = requestId,
            });

            if (!saveWarrantyResponse.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(saveWarrantyRequest.Failure !));
            }

            var validateResponse = ResponseValidator.Validate(request, operation, requestId, rawResponse);

            if (!validateResponse.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(validateResponse.Failure !));
            }

            var convertResponse = ResponseConverter.Convert(request, operation, requestId, rawResponse);

            if (!convertResponse.IsSuccess)
            {
                return(new Result <WarrantyCaseResponse, IFailure>(convertResponse.Failure !));
            }
            var convertedResponse = convertResponse.Success !;

            if (operation == WarrantyCaseOperation.Commit &&
                convertedResponse.WarrantyCaseStatus == WarrantyCaseStatus.Committed)
            {
                var saveWarrantyProof = await ComprehensiveDataWrapper.SaveWarrantyProof(
                    new WarrantyProof(
                        orderId : request.OrderId,
                        warrantyCaseId : convertedResponse.WarrantyCaseId,
                        proof : rawResponse.Body !.OrderReports.Single().WarrantyProof !)
                {
                    RequestId = requestId,
                });