public When_OpportunityProximityService_Is_Called_To_Search_Opportunities_By_Postcode_Proximity() { var dto = new OpportunityProximitySearchParametersDto { Postcode = Postcode, SearchRadius = SearchRadius, SelectedRouteId = RouteId }; _searchProvider = Substitute.For <ISearchProvider>(); _searchProvider .SearchOpportunitiesByPostcodeProximityAsync(dto) .Returns(new SearchResultsBuilder().Build()); _locationService = Substitute.For <ILocationService>(); _locationService.GetGeoLocationDataAsync(Postcode) .Returns(new PostcodeLookupResultDto { Postcode = Postcode, Longitude = "1.2", Latitude = "1.2" }); var service = new OpportunityProximityService(_searchProvider, _locationService); _result = service.SearchOpportunitiesByPostcodeProximityAsync(dto).GetAwaiter().GetResult(); }
public async Task <IList <OpportunityProximitySearchResultByRouteViewModelItem> > SearchOpportunitiesForOtherRoutesByPostcodeProximityAsync(OpportunityProximitySearchParametersDto dto) { var geoLocationData = await _locationService.GetGeoLocationDataAsync(dto.Postcode); dto.Latitude = geoLocationData.Latitude; dto.Longitude = geoLocationData.Longitude; var searchResults = await _searchProvider.SearchOpportunitiesForOtherRoutesByPostcodeProximityAsync(dto); var results = searchResults.Any() ? searchResults : new List <OpportunityProximitySearchResultByRouteViewModelItem>(); return(results); }
public async Task <IList <OpportunityProximitySearchResultByRouteViewModelItem> > SearchOpportunitiesForOtherRoutesByPostcodeProximityAsync(OpportunityProximitySearchParametersDto dto) { _logger.LogInformation($"Searching for opportunities within radius {dto.SearchRadius} of postcode '{dto.Postcode}' with route other than {dto.SelectedRouteId}"); var employerLocation = GetSearchStartPoint(dto.Latitude, dto.Longitude); var searchRadiusInMeters = dto.SearchRadius * MilesToMeters; var result = await(from provider in _matchingDbContext.Provider join providerVenue in _matchingDbContext.ProviderVenue on provider.Id equals providerVenue.ProviderId join providerQualification in _matchingDbContext.ProviderQualification on providerVenue.Id equals providerQualification.ProviderVenueId join qualificationRouteMapping in _matchingDbContext.QualificationRouteMapping on providerQualification.QualificationId equals qualificationRouteMapping.QualificationId join route in _matchingDbContext.Route on qualificationRouteMapping.RouteId equals route.Id orderby route.Name where qualificationRouteMapping.RouteId != dto.SelectedRouteId && providerVenue.Location.Distance(employerLocation) <= searchRadiusInMeters && provider.IsCdfProvider && provider.IsEnabledForReferral && providerVenue.IsEnabledForReferral && !providerVenue.IsRemoved select new { ProviderVenueId = providerVenue.Id, RouteName = route.Name }).Distinct().ToListAsync(); return(result .GroupBy(r => r.RouteName) .Select(rg => new OpportunityProximitySearchResultByRouteViewModelItem { RouteName = rg.Key.ToLower(), NumberOfResults = rg.Count() }).OrderBy(r => r.RouteName).ToList()); }
public async Task <IList <OpportunityProximitySearchResultViewModelItem> > SearchOpportunitiesByPostcodeProximityAsync(OpportunityProximitySearchParametersDto dto) { var geoLocationData = await _locationService.GetGeoLocationDataAsync(dto.Postcode); dto.Latitude = geoLocationData.Latitude; dto.Longitude = geoLocationData.Longitude; var searchResults = await _searchProvider.SearchOpportunitiesByPostcodeProximityAsync(dto); return(searchResults ?? new List <OpportunityProximitySearchResultViewModelItem>()); }
public async Task <IList <OpportunityProximitySearchResultViewModelItem> > SearchOpportunitiesByPostcodeProximityAsync(OpportunityProximitySearchParametersDto dto) { _logger.LogInformation($"Searching for opportunities within radius {dto.SearchRadius} of postcode '{dto.Postcode}' with route {dto.SelectedRouteId}"); var employerLocation = GetSearchStartPoint(dto.Latitude, dto.Longitude); var searchRadiusInMeters = dto.SearchRadius * MilesToMeters; var result = await(from provider in _matchingDbContext.Provider join providerVenue in _matchingDbContext.ProviderVenue on provider.Id equals providerVenue.ProviderId join providerQualification in _matchingDbContext.ProviderQualification on providerVenue.Id equals providerQualification.ProviderVenueId join qualificationRouteMapping in _matchingDbContext.QualificationRouteMapping on providerQualification.QualificationId equals qualificationRouteMapping.QualificationId join qualification in _matchingDbContext.Qualification on qualificationRouteMapping.QualificationId equals qualification.Id orderby providerVenue.Location.Distance(employerLocation) where qualificationRouteMapping.RouteId == dto.SelectedRouteId && providerVenue.Location.Distance(employerLocation) <= searchRadiusInMeters && provider.IsCdfProvider && provider.IsEnabledForReferral && providerVenue.IsEnabledForReferral && !providerVenue.IsRemoved select new { ProviderVenueId = providerVenue.Id, ProviderName = provider.Name, ProviderDisplayName = provider.DisplayName, ProviderVenueName = providerVenue.Name, Distance = providerVenue.Location.Distance(employerLocation) / MilesToMeters, providerVenue.Postcode, providerVenue.Town, providerVenue.Latitude, providerVenue.Longitude, provider.IsTLevelProvider, QualificationShortTitle = qualification.ShortTitle }).Distinct().ToListAsync(); return(result.GroupBy(grp => new { grp.ProviderVenueId, grp.ProviderName, grp.ProviderDisplayName, grp.ProviderVenueName, grp.Distance, grp.Postcode, grp.Town, grp.Latitude, grp.Longitude, grp.IsTLevelProvider }) .Select(g => new OpportunityProximitySearchResultViewModelItem { ProviderVenueTown = g.Key.Town, ProviderVenuePostcode = g.Key.Postcode, ProviderVenueId = g.Key.ProviderVenueId, ProviderName = g.Key.ProviderName, ProviderDisplayName = g.Key.ProviderDisplayName, ProviderVenueName = g.Key.ProviderVenueName, Distance = g.Key.Distance, IsTLevelProvider = g.Key.IsTLevelProvider, Latitude = g.Key.Latitude ?? 0, Longitude = g.Key.Longitude ?? 0, QualificationShortTitles = g.Select(q => q.QualificationShortTitle) }).OrderBy(r => r.Distance).ToList()); }