public async Task <GetAdvertsQueryResult> Handle(GetAdvertsQuery request, CancellationToken cancellationToken) { var routesTask = _courseService.GetRoutes(); var standardsTask = _courseService.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse)); var locationTask = _locationLookupService.GetLocationInformation(request.Postcode, 0, 0); await Task.WhenAll(routesTask, locationTask, standardsTask); if (locationTask.Result == null) { return(new GetAdvertsQueryResult { Routes = routesTask.Result.Routes, Vacancies = new List <GetVacanciesListItem>() }); } var standardLarsCode = standardsTask.Result.Standards.Where(c => c.Route.Equals(request.Route, StringComparison.CurrentCultureIgnoreCase)).Select(c => c.LarsCode).ToList(); var apprenticeshipVacancies = new List <GetVacanciesListItem>(); var skip = 0; var take = 15; while (true) { var standards = standardLarsCode.Skip(skip).Take(take).ToList(); if (standards.Count == 0) { break; } var advertRequest = new GetVacanciesRequest(0, 20, null, null, null, standards, null, locationTask.Result.GeoPoint.FirstOrDefault(), locationTask.Result.GeoPoint.LastOrDefault(), request.Distance, null, null, "DistanceAsc"); var adverts = await _findApprenticeshipApiClient.Get <GetVacanciesResponse>(advertRequest); apprenticeshipVacancies.AddRange(adverts.ApprenticeshipVacancies.ToList()); skip += take; } foreach (var advert in apprenticeshipVacancies) { advert.VacancyUrl = $"{_configuration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{advert.VacancyReference}"; } return(new GetAdvertsQueryResult { Location = locationTask.Result, Routes = routesTask.Result.Routes, TotalFound = apprenticeshipVacancies.Count, Vacancies = apprenticeshipVacancies.OrderBy(c => c.Distance).Take(20) }); }
public async Task <GetVacancyQueryResult> Handle(GetVacancyQuery request, CancellationToken cancellationToken) { var vacancyResponseTask = _findApprenticeshipApiClient.Get <GetVacancyApiResponse>( new GetVacancyRequest(request.VacancyReference)); var standardsTask = _standardsService.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse)); await Task.WhenAll(vacancyResponseTask, standardsTask); if (vacancyResponseTask.Result == null) { return(new GetVacancyQueryResult { Vacancy = null }); } vacancyResponseTask.Result.VacancyUrl = vacancyResponseTask.Result.VacancyUrl = $"{_vacanciesConfiguration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancyResponseTask.Result.VacancyReference}"; if (vacancyResponseTask.Result.StandardLarsCode != null) { var standard = standardsTask.Result.Standards.SingleOrDefault(c => c.LarsCode.Equals(vacancyResponseTask.Result.StandardLarsCode)); if (standard != null) { vacancyResponseTask.Result.CourseLevel = standard.Level; vacancyResponseTask.Result.CourseTitle = standard.Title; vacancyResponseTask.Result.Route = standard.Route; } } return(new GetVacancyQueryResult { Vacancy = vacancyResponseTask.Result }); }
public async Task <GetVacanciesQueryResult> Handle(GetVacanciesQuery request, CancellationToken cancellationToken) { if (!string.IsNullOrEmpty(request.AccountLegalEntityPublicHashedId)) { switch (request.AccountIdentifier.AccountType) { case AccountType.Unknown: throw new SecurityException(); case AccountType.External: request.AccountLegalEntityPublicHashedId = string.Empty; request.AccountPublicHashedId = string.Empty; break; default: { var accountLegalEntity = await _accountLegalEntityPermissionService.GetAccountLegalEntity(request.AccountIdentifier, request.AccountLegalEntityPublicHashedId); if (accountLegalEntity == null) { throw new SecurityException(); } break; } } } var categories = _courseService.MapRoutesToCategories(request.Routes); var vacanciesTask = _findApprenticeshipApiClient.Get <GetVacanciesResponse>(new GetVacanciesRequest( request.PageNumber, request.PageSize, request.AccountLegalEntityPublicHashedId, request.Ukprn, request.AccountPublicHashedId, request.StandardLarsCode, request.NationWideOnly, request.Lat, request.Lon, request.DistanceInMiles, categories, request.PostedInLastNumberOfDays, request.Sort)); var standardsTask = _courseService.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse)); await Task.WhenAll(vacanciesTask, standardsTask); foreach (var vacanciesItem in vacanciesTask.Result.ApprenticeshipVacancies) { if (vacanciesItem.StandardLarsCode == null) { continue; } var standard = standardsTask.Result.Standards.FirstOrDefault( c => c.LarsCode.Equals(vacanciesItem.StandardLarsCode)); if (standard != null) { vacanciesItem.CourseTitle = standard.Title; vacanciesItem.Route = standard.Route; vacanciesItem.CourseLevel = standard.Level; } vacanciesItem.VacancyUrl = $"{_vacanciesConfiguration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacanciesItem.VacancyReference}"; } return(new GetVacanciesQueryResult() { Vacancies = vacanciesTask.Result.ApprenticeshipVacancies.Where(c => c.StandardLarsCode != null).ToList(), Total = vacanciesTask.Result.Total, TotalFiltered = vacanciesTask.Result.TotalFound, TotalPages = request.PageSize != 0 ? (int)Math.Ceiling((decimal)vacanciesTask.Result.TotalFound / request.PageSize) : 0 }); }