private void ThrowBadRequestIfAllAreExcluded(SearchLegalPartyQueryDto legalPartySearchDto) { var accessor = TypeAccessor.Create(typeof(SearchLegalPartyQueryDto)); var members = accessor.GetMembers().Where(x => x.Type == typeof(bool?) && x.Name.StartsWith("Exclude")).ToList(); var totalExclusions = members.Count(x => (bool?)accessor[legalPartySearchDto, x.Name] == true); if (totalExclusions == members.Count) { throw new BadRequestException("All search parameters are excluded. At least one search parameter must be enabled."); } }
public void SearchAsyncShouldOnlyReturnUpToMaxRowsFromConfig() { var list = new List <SearchLegalParty> { new SearchLegalParty { DisplayName = "", Address = " 123 bar st " } }; _legalPartyRepositoryMock.Setup(x => x.SearchAsync("bar", It.IsAny <SearchLegalPartyQuery>())).ReturnsAsync(list); var searchLegalPartyQueryDto = new SearchLegalPartyQueryDto { SearchText = "bar", MaxRows = 50000 }; var results = _legalPartyDomain.SearchAsync(searchLegalPartyQueryDto).Result.ToList(); searchLegalPartyQueryDto.MaxRows.ShouldBe(35000); }
public static SearchLegalPartyQuery ToExclusions(this SearchLegalPartyQueryDto searchLegalPartyQueryDto) { return(Mapper.Map(searchLegalPartyQueryDto, new SearchLegalPartyQuery())); }
public async Task <IActionResult> Search([FromBody] SearchLegalPartyQueryDto searchLegalPartyQueryDto) { return(new ObjectResult(await _searchLegalPartyDomain.SearchAsync(searchLegalPartyQueryDto))); }
public async Task <IEnumerable <SearchLegalPartyDto> > SearchAsync(SearchLegalPartyQueryDto legalPartySearchDto) { if (string.IsNullOrEmpty(legalPartySearchDto.SearchText)) { throw new BadRequestException("SearchText cannot be null."); } if (legalPartySearchDto.MaxRows > _searchResultsConfiguration.MaxRows) { legalPartySearchDto.MaxRows = _searchResultsConfiguration.MaxRows; } legalPartySearchDto.SearchText = legalPartySearchDto.SearchText.Trim(); ThrowBadRequestIfAllAreExcluded(legalPartySearchDto); var searchProvider = _searchProviderSelector.Get(legalPartySearchDto.SearchText); CacheMaxRowIfMaxRowIsValid(legalPartySearchDto.MaxRows); IEnumerable <SearchLegalParty> results = null; var isPin = IsPin(legalPartySearchDto.SearchText, new List <SearchLegalParty>()); if (isPin) { var searchLegalPartyQueryExclusions = legalPartySearchDto.ToExclusions(); searchLegalPartyQueryExclusions.ExcludeAddress = true; searchLegalPartyQueryExclusions.ExcludeDisplayName = true; searchLegalPartyQueryExclusions.ExcludeAin = false; searchLegalPartyQueryExclusions.ExcludePin = false; searchLegalPartyQueryExclusions.ExcludeSearchAll = true; searchLegalPartyQueryExclusions.ExcludeTag = false; bool isActive = legalPartySearchDto.IsActive ?? true; results = await searchProvider.Provider .SearchPinAsync(searchProvider.ParsedSearchText, searchLegalPartyQueryExclusions, isActive, legalPartySearchDto.EffectiveDate); } else { if (legalPartySearchDto.EffectiveDate.HasValue || legalPartySearchDto.IsActive.HasValue) { results = await searchProvider.Provider.SearchAsync( searchProvider.ParsedSearchText, legalPartySearchDto.ToExclusions(), legalPartySearchDto.IsActive, legalPartySearchDto.EffectiveDate); } else { results = await searchProvider.Provider.SearchAsync( searchProvider.ParsedSearchText, legalPartySearchDto.ToExclusions()); } } results = SearchLegalParties(searchProvider.ParsedSearchText, legalPartySearchDto.ToExclusions(), legalPartySearchDto.EffectiveDate, results.ToList()); var records = results.Select(x => x.ToDomain()).ToList(); _logger.LogDebug($"Found {records.Count} records."); return(records); }