Ejemplo n.º 1
0
        public IActionResult GetSuggestions(string q, double?latitude, double?longitude, int?n)
        {
            List <SuggestionDto> weightedResults;
            var defaultResultSize = 10;

            // Make sure q does not equal "", ", '', ' and empty
            if (!q.IsValidInput())
            {
                return(BadRequest(new BadRequestError("The q paramter is mandatory")));
            }

            if (_trie.Trie.IsEmpty())
            {
                _seedDomainService.ResetPrefixTree();
            }

            if (n.HasValue && n >= 0)
            {
                defaultResultSize = n.Value;
            }

            var coords = new GeographicalLocation(latitude, longitude);

            if (coords.Latitude.HasValue || coords.Longitude.HasValue)
            {
                if (!coords.AreCoordinatesValid())
                {
                    return(BadRequest(new BadRequestError("Latitude and logitude are not proper format")));
                }
            }

            //Fetch suggestions
            var results = _trie.Trie.GetSuggestionsForPrefix(q.SanitizeInput()).ToList();

            //Add score to values
            if (coords.AreCoordinatesValid())
            {
                weightedResults = _scoringDomainService.WeightedSuggestionsWithCoordinates(results, defaultResultSize, coords);
            }
            else
            {
                weightedResults = _scoringDomainService.WeightedSuggestions(results, defaultResultSize);
            }

            return(Ok(weightedResults));
        }
Ejemplo n.º 2
0
        public void AreCoordinatesValid_ShouldReturnFalse_ForNotValidCoordinates(double latitude, double longitude)
        {
            // Arrange
            var coords = new GeographicalLocation(latitude, longitude);

            //Act
            var result = coords.AreCoordinatesValid();

            //Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldBeFalse()
                );
        }
Ejemplo n.º 3
0
        public void AreCoordinatesValid_ShouldReturnTrue_ForValidCoordinates()
        {
            // Arrange
            var coords = new GeographicalLocation(43.70011, -79.4163);

            //Act
            var result = coords.AreCoordinatesValid();

            //Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldBeTrue()
                );
        }