public IHttpActionResult GetPinsByAddress(PinSearchQueryParams queryParams) { try { AwsBoundingBox awsBoundingBox = null; Boolean areAllBoundingBoxParamsPresent = _finderService.areAllBoundingBoxParamsPresent(queryParams.BoundingBox); if (areAllBoundingBoxParamsPresent) { awsBoundingBox = _awsCloudsearchService.BuildBoundingBox(queryParams.BoundingBox); } var originCoords = _finderService.GetMapCenterForResults(queryParams.UserLocationSearchString, queryParams.CenterGeoCoords, queryParams.FinderType); var pinsInRadius = _finderService.GetPinsInBoundingBox(originCoords, queryParams.UserKeywordSearchString, awsBoundingBox, queryParams.FinderType, queryParams.ContactId, queryParams.UserFilterString); pinsInRadius = _finderService.RandomizeLatLongForNonSitePins(pinsInRadius); var result = new PinSearchResultsDto(new GeoCoordinates(originCoords.Latitude, originCoords.Longitude), pinsInRadius); return(Ok(result)); } catch (InvalidAddressException ex) { var apiError = new ApiErrorDto("Invalid Address", ex, HttpStatusCode.PreconditionFailed); throw new HttpResponseException(apiError.HttpResponseMessage); } catch (Exception ex) { var apiError = new ApiErrorDto("Get Pin By Address Failed", ex); throw new HttpResponseException(apiError.HttpResponseMessage); } }
public void TestGetMyPinsByContactIdReturnsNothing() { var fakeQueryParams = new PinSearchQueryParams(); fakeQueryParams.CenterGeoCoords = new GeoCoordinates(39.123, -84.456); fakeQueryParams.ContactId = 12345; fakeQueryParams.FinderType = "CONNECT"; var geoCoordinate = new GeoCoordinate(39.123, -84.456); _finderService.Setup(m => m.GetGeoCoordsFromAddressOrLatLang(It.IsAny <string>(), It.IsAny <GeoCoordinates>())).Returns(geoCoordinate); _finderService.Setup(m => m.GetMyPins(It.IsAny <string>(), It.IsAny <GeoCoordinate>(), It.IsAny <int>(), It.IsAny <string>())).Returns(new List <PinDto>()); var response = _fixture.GetMyPinsByContactId(fakeQueryParams) as OkNegotiatedContentResult <PinSearchResultsDto>; Assert.That(response != null && response.Content.PinSearchResults.Count == 0); }
public void TestGetMyPinsByContactIdWithResults() { var fakeQueryParams = new PinSearchQueryParams(); fakeQueryParams.CenterGeoCoords = new GeoCoordinates(39.123, -84.456); fakeQueryParams.ContactId = 12345; fakeQueryParams.FinderType = "CONNECT"; var geoCoordinate = new GeoCoordinate(39.123, -84.456); var listPinDto = GetListOfPinDto(); var address = new AddressDTO("123 Main st", "", "Independence", "KY", "41051", 32, -84); _finderService.Setup(m => m.GetGeoCoordsFromAddressOrLatLang(It.IsAny <string>(), It.IsAny <GeoCoordinates>())).Returns(geoCoordinate); _finderService.Setup(m => m.GetMyPins(It.IsAny <string>(), It.IsAny <GeoCoordinate>(), It.IsAny <int>(), It.IsAny <string>())).Returns(listPinDto); _finderService.Setup(m => m.RandomizeLatLong(It.IsAny <AddressDTO>())).Returns(address); var response = _fixture.GetMyPinsByContactId(fakeQueryParams); Assert.IsNotNull(response); Assert.IsInstanceOf <OkNegotiatedContentResult <PinSearchResultsDto> >(response); }
public IHttpActionResult GetMyPinsByContactId(PinSearchQueryParams queryParams) { return(Authorized(token => { try { var originCoords = _finderService.GetGeoCoordsFromAddressOrLatLang(queryParams.UserLocationSearchString, queryParams.CenterGeoCoords); var centerLatitude = originCoords.Latitude; var centerLongitude = originCoords.Longitude; var pinsForContact = _finderService.GetMyPins(token, originCoords, queryParams.ContactId, queryParams.FinderType); if (pinsForContact.Count > 0) { var addressLatitude = pinsForContact[0].Address.Latitude; if (addressLatitude != null) { centerLatitude = (double)addressLatitude != 0.0 ? (double)addressLatitude : originCoords.Latitude; } var addressLongitude = pinsForContact[0].Address.Longitude; if (addressLongitude != null) { centerLongitude = (double)addressLongitude != 0.0 ? (double)addressLongitude : originCoords.Longitude; } } var result = new PinSearchResultsDto(new GeoCoordinates(centerLatitude, centerLongitude), pinsForContact); return Ok(result); } catch (Exception ex) { var apiError = new ApiErrorDto("Get Pins for My Stuff Failed", ex); throw new HttpResponseException(apiError.HttpResponseMessage); } })); }