private async Task <int> RefreshApprenticeshipVacanciesAsync(CurrentOpportunitiesSegmentModel currentOpportunitiesSegmentModel) { var aVMapping = new AVMapping() { Standards = currentOpportunitiesSegmentModel.Data.Apprenticeships?.Standards?.Where(w => !string.IsNullOrWhiteSpace(w.Url)).Select(b => b.Url).ToArray(), Frameworks = currentOpportunitiesSegmentModel.Data.Apprenticeships?.Frameworks?.Where(w => !string.IsNullOrWhiteSpace(w.Url)).Select(b => b.Url).ToArray(), }; var vacancies = new List <Vacancy>(); if (aVMapping.Standards.Any() || aVMapping.Frameworks.Any()) { var mappedVacancies = await aVAPIService.GetAVsForMultipleProvidersAsync(aVMapping).ConfigureAwait(false); var projectedVacancies = ProjectVacanciesForProfile(mappedVacancies); //projectedVacancies will contain at most 2 records foreach (var vacancy in projectedVacancies) { var projectedVacancyDetails = await aVAPIService.GetApprenticeshipVacancyDetailsAsync(vacancy.VacancyReference).ConfigureAwait(false); vacancies.Add(mapper.Map <Vacancy>(projectedVacancyDetails)); logger.LogInformation($"{nameof(RefreshApprenticeshipVacanciesAsync)} added details for {vacancy.VacancyReference} to list"); } } else { logger.LogInformation($"{nameof(RefreshApprenticeshipVacanciesAsync)} no standards or frameworks found for document {currentOpportunitiesSegmentModel.DocumentId}, blanking vacancies"); } currentOpportunitiesSegmentModel.Data.Apprenticeships.Vacancies = vacancies; await repository.UpsertAsync(currentOpportunitiesSegmentModel).ConfigureAwait(false); return(vacancies.Count); }
public AVAPIServiceTests() { fakeLogger = A.Fake <ILogger <AVAPIService> >(); aVAPIServiceSettings = new AVAPIServiceSettings() { FAAMaxPagesToTryPerMapping = 100 }; fakeApprenticeshipVacancyApi = A.Fake <IApprenticeshipVacancyApi>(); aVMapping = new AVMapping { Standards = new string[] { "225" }, Frameworks = new string[] { "512" }, }; }
public async Task <ApprenticeshipVacancySummaryResponse> GetAVSumaryPageAsync(AVMapping mapping, int pageNumber) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } logger.LogInformation($"Extracting AV summaries for Standards = {mapping.Frameworks} Frameworks = {mapping.Standards} page : {pageNumber}"); var queryString = HttpUtility.ParseQueryString(string.Empty); if (mapping.Standards != null) { queryString["standardLarsCodes"] = string.Join(",", mapping.Standards.Where(s => !string.IsNullOrWhiteSpace(s))); } if (mapping.Frameworks != null) { queryString["frameworkLarsCodes"] = string.Join(",", mapping.Frameworks.Where(s => !string.IsNullOrWhiteSpace(s))); } queryString["pageSize"] = $"{aVAPIServiceSettings.FAAPageSize}"; queryString["pageNumber"] = $"{pageNumber}"; queryString["sortBy"] = aVAPIServiceSettings.FAASortBy; var responseResult = await apprenticeshipVacancyApi.GetAsync(queryString.ToString(), RequestType.Search).ConfigureAwait(false); return(JsonConvert.DeserializeObject <ApprenticeshipVacancySummaryResponse>(responseResult)); }
public async Task <IEnumerable <ApprenticeshipVacancySummary> > GetAVsForMultipleProvidersAsync(AVMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } List <ApprenticeshipVacancySummary> avSummary = new List <ApprenticeshipVacancySummary>(); var pageNumber = 0; logger.LogInformation($"Getting vacancies for mapping {JsonConvert.SerializeObject(mapping)}"); //Allways break after a given number off loops while (aVAPIServiceSettings.FAAMaxPagesToTryPerMapping > pageNumber) { var apprenticeshipVacancySummaryResponse = await GetAVSumaryPageAsync(mapping, ++pageNumber).ConfigureAwait(false); logger.LogInformation($"Got {apprenticeshipVacancySummaryResponse.TotalReturned} vacancies of {apprenticeshipVacancySummaryResponse.TotalMatched} on page: {pageNumber} of {apprenticeshipVacancySummaryResponse.TotalPages}"); avSummary.AddRange(apprenticeshipVacancySummaryResponse.Results); //stop when there are no more pages or we have more then multiple supplier if (apprenticeshipVacancySummaryResponse.TotalPages < pageNumber || avSummary.Select(v => v.TrainingProviderName).Distinct().Count() > 1) { break; } } return(avSummary); }