예제 #1
0
 public async Task <IEnumerable <Apprenticeship> > GetDraftApprenticeships(Cohort cohort)
 {
     try
     {
         return(await _pollyPolicy.ExecuteAsync(() => _commitmentsV2Service.GetDraftApprenticeships(cohort)));
     }
     catch (TimeoutRejectedException ex)
     {
         throw new ServiceTimeoutException("Call to Commitments V2 Service timed out", ex);
     }
 }
        public async Task <GetSingleCohortResponse> Handle(GetSingleCohortRequest message)
        {
            var validationResult = _validator.Validate(message);

            if (!validationResult.IsValid())
            {
                throw new InvalidRequestException(validationResult.ValidationDictionary);
            }

            long accountId = _hashingService.DecodeValue(message.HashedAccountId);

            try
            {
                var cohortsResponse = await _commitmentV2Service.GetCohorts(accountId);

                if (cohortsResponse.Count() != 1)
                {
                    return(new GetSingleCohortResponse());
                }

                var singleCohort = cohortsResponse.Single();

                if (singleCohort.NumberOfDraftApprentices > 0)
                {
                    singleCohort.Apprenticeships = await _commitmentV2Service.GetDraftApprenticeships(singleCohort);
                }
                return(new GetSingleCohortResponse
                {
                    Cohort = singleCohort
                });
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Failed to get Cohorts for {message.HashedAccountId}");
                return(new GetSingleCohortResponse
                {
                    HasFailed = true
                });
            }
        }