public async Task <GroupedProviderSearchResults> SearchProvidersWithGroupedResults(string apprenticeshipId, string postCode, Pagination pagination, bool hasNonLevyContract, bool showNationalOnly)
        {
            if (string.IsNullOrEmpty(postCode))
            {
                return(new GroupedProviderSearchResults {
                    PostCodeMissing = true
                });
            }

            try
            {
                var coordinateResponse = await _postCodeLookup.GetLatLongFromPostCode(postCode);

                var coordinates = coordinateResponse.Coordinate;


                if (coordinateResponse.ResponseCode != LocationLookupResponse.Ok)
                {
                    return(GetGroupedProviderSearchResultErrorResponse(postCode, coordinateResponse.ResponseCode));
                }

                var takeElements = pagination.Take == 0 ? _paginationSettings.DefaultResultsAmount : pagination.Take;

                LogSearchRequest(postCode, coordinates);

                var filter = new ProviderSearchFilter
                {
                    DeliveryModes      = null,
                    HasNonLevyContract = hasNonLevyContract,
                    ShowNationalOnly   = showNationalOnly
                };

                var searchResults = await _providerSearchProvider.SearchProvidersByLocationGroupByProvider(apprenticeshipId, coordinates, pagination.Page, takeElements, filter);

                var result = new GroupedProviderSearchResults
                {
                    TotalResults              = searchResults.Total,
                    ResultsToTake             = takeElements,
                    PostCode                  = postCode,
                    ShowNationalProvidersOnly = false,
                    Hits                 = searchResults.Hits,
                    LastPage             = takeElements > 0 ? (int)System.Math.Ceiling((double)searchResults.Total / takeElements) : 1,
                    HasNationalProviders = searchResults.HasNationalProviders
                };

                return(result);
            }
            catch (SearchException ex)
            {
                _logger.Error(ex, "Search for provider failed.");

                return(GetGroupedProviderSearchResultErrorResponse(postCode, ServerLookupResponse.InternalServerError));
            }
        }
 public void Setup()
 {
     _providerSearchFilter = new ProviderSearchFilter()
     {
         DeliveryModes = new List <string>()
         {
             "0", "1", "2"
         }
     };
     _mockProviderV3ApiClient.Setup(s =>
                                    s.GetByApprenticeshipIdAndLocationAsync(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>(), 0))
     .ReturnsAsync(new SFADASApprenticeshipsApiTypesV3ProviderApprenticeshipLocationSearchResult()
     {
     });
     _mockSearchResultsMapping.Setup(s => s.Map(It.IsAny <SFADASApprenticeshipsApiTypesV3ProviderApprenticeshipLocationSearchResult>())).Returns(new ProviderSearchResult <ProviderSearchResultItem>());
 }
 public SearchResult <FrameworkProviderSearchResultsItem> SearchFrameworkProviders(string frameworkId, Coordinate coordinates, int page, int take, ProviderSearchFilter filter)
 {
     throw new NotImplementedException();
 }
 public SearchResult <StandardProviderSearchResultsItem> SearchStandardProviders(string standardId, Coordinate coordinates, int page, int take, ProviderSearchFilter filter)
 {
     throw new NotImplementedException();
 }
        public async Task <ProviderSearchResults> SearchProviders(string apprenticeshipId, string postCode, Pagination pagination, IEnumerable <string> deliveryModes, bool hasNonLevyContract, bool showNationalOnly, int orderBy = 0)
        {
            if (string.IsNullOrEmpty(postCode))
            {
                return(new ProviderSearchResults {
                    ApprenticeshipId = apprenticeshipId, PostCodeMissing = true
                });
            }

            int apprenticeshipIdInt;

            IApprenticeshipProduct apprenticeship;

            if (int.TryParse(apprenticeshipId, out apprenticeshipIdInt))
            {
                apprenticeship = _getStandards.GetStandardById(apprenticeshipId);
            }
            else
            {
                apprenticeship = _getFrameworks.GetFrameworkById(apprenticeshipId);
            }

            if (apprenticeship == null)
            {
                return(GetProviderSearchResultErrorResponse(apprenticeshipId, null, postCode, LocationLookupResponse.ApprenticeshipNotFound));
            }

            try
            {
                var coordinateResponse = await _postCodeLookup.GetLatLongFromPostCode(postCode);

                var coordinates = coordinateResponse.Coordinate;


                if (coordinateResponse.ResponseCode != LocationLookupResponse.Ok)
                {
                    return(GetProviderSearchResultErrorResponse(apprenticeshipId, apprenticeship?.Title, postCode, coordinateResponse.ResponseCode));
                }

                var takeElements = pagination.Take == 0 ? _paginationSettings.DefaultResultsAmount : pagination.Take;

                LogSearchRequest(postCode, coordinates);

                var filter = new ProviderSearchFilter
                {
                    DeliveryModes      = deliveryModes,
                    HasNonLevyContract = hasNonLevyContract,
                    ShowNationalOnly   = showNationalOnly
                };

                var searchResults = await _providerSearchProvider.SearchProvidersByLocation(apprenticeshipId, coordinates, pagination.Page, takeElements, filter, orderBy);

                var result = new ProviderSearchResults
                {
                    TotalResults               = searchResults.Total,
                    ResultsToTake              = takeElements,
                    ApprenticeshipId           = apprenticeshipId,
                    Title                      = apprenticeship?.Title,
                    Level                      = apprenticeship.Level,
                    PostCode                   = postCode,
                    TrainingOptionsAggregation = searchResults.TrainingOptionsAggregation,
                    NationalProviders          = searchResults.NationalProvidersAggregation,
                    SelectedTrainingOptions    = deliveryModes,
                    ResponseCode               = LocationLookupResponse.Ok,
                    ShowNationalProvidersOnly  = false,
                    Hits     = searchResults.Hits,
                    LastPage = takeElements > 0 ? (int)System.Math.Ceiling((double)searchResults.Total / takeElements) : 1
                };

                return(result);
            }
            catch (SearchException ex)
            {
                _logger.Error(ex, "Search for provider failed.");

                return(GetProviderSearchResultErrorResponse(apprenticeshipId, apprenticeship?.Title, postCode, ServerLookupResponse.InternalServerError));
            }
        }
Example #6
0
        public async Task <GroupedProviderSearchResult <GroupedProviderSearchResultItem> > SearchProvidersByLocationGroupByProvider(string apprenticeshipId, Coordinate coordinates, int page, int take, ProviderSearchFilter filter)
        {
            var result = await _searchV4Api.GetByApprenticeshipIdAndLatLon(apprenticeshipId, coordinates.Lat, coordinates.Lon, page, take, filter.HasNonLevyContract, filter.ShowNationalOnly);

            return(_searchResultsMapping.Map(result));
        }
Example #7
0
        public async Task <ProviderSearchResult <ProviderSearchResultItem> > SearchProvidersByLocation(string apprenticeshipId, Coordinate coordinates, int page, int take, ProviderSearchFilter filter, int orderBy = 0)
        {
            var deliveryModes = new List <string>();

            foreach (var filterDeliveryMode in filter.DeliveryModes)
            {
                switch (filterDeliveryMode)
                {
                case "dayrelease":
                    deliveryModes.Add("0");
                    break;

                case "blockrelease":
                    deliveryModes.Add("1");
                    break;

                case "100percentemployer":
                    deliveryModes.Add("2");
                    break;

                default:
                    deliveryModes.Add(filterDeliveryMode);
                    break;
                }
            }

            var result = await _providersV3Api.GetByApprenticeshipIdAndLocationAsync(apprenticeshipId, coordinates.Lat, coordinates.Lon, page, take, filter.HasNonLevyContract, filter.ShowNationalOnly, string.Join(",", deliveryModes), orderBy);

            return(_searchResultsMapping.Map(result));
        }