public async Task <DraftViewModel> Map(CohortsByAccountRequest source)
        {
            var request = new GetCohortsRequest {
                AccountId = source.AccountId
            };
            var apiResponse = await _commitmentsApiClient.GetCohorts(request);

            var cohorts = apiResponse.Cohorts
                          .Where(x => x.GetStatus() == CohortStatus.Draft)
                          .OrderByDescending(x => x.CreatedOn)
                          .Select(x => new DraftCohortSummaryViewModel
            {
                ProviderName        = x.ProviderName,
                CohortReference     = _encodingService.Encode(x.CohortId, EncodingType.CohortReference),
                NumberOfApprentices = x.NumberOfDraftApprentices,
            }).ToList();

            return(new DraftViewModel
            {
                AccountHashedId = source.AccountHashedId,
                ApprenticeshipRequestsHeaderViewModel = apiResponse.Cohorts.GetCohortCardLinkViewModel(_urlHelper, source.AccountHashedId, CohortStatus.Draft),
                AccountId = source.AccountId,
                Cohorts = cohorts
            });
        }
        public async Task <IActionResult> GetCohorts([FromQuery] GetCohortsRequest request)
        {
            var query  = new GetCohortsQuery(request.AccountId, request.ProviderId);
            var result = await _mediator.Send(query);

            return(Ok(new GetCohortsResponse(result.Cohorts)));
        }
        public async Task GetCohorts_VerifyUrlAndDataIsCorrectPassedIn()
        {
            var request = new GetCohortsRequest {
                AccountId = 123
            };
            await _fixture.CommitmentsApiClient.GetCohorts(request);

            _fixture.MockRestHttpClient.Verify(x => x.Get <GetCohortsResponse>("api/cohorts", request, CancellationToken.None));
        }
        public void Validate_AccountIdAndProviderId_ShouldBeValidated(long?accountId, long?providerId, bool expectedValid)
        {
            var request = new GetCohortsRequest {
                AccountId = accountId, ProviderId = providerId
            };
            var validator = new GetCohortsRequestValidator();

            var result = validator.TestValidate(request);

            Assert.AreEqual(expectedValid, result.Result.IsValid);
        }
Example #5
0
 public Task <GetCohortsResponse> GetCohorts(GetCohortsRequest request, CancellationToken cancellationToken = default)
 {
     return(_client.Get <GetCohortsResponse>($"api/cohorts", request, cancellationToken));
 }