Skip to content

Commit

Permalink
backend/feat/#91 Add Fields In autocomplete API
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikrant Mahto authored and Vikrant Mahto committed Apr 25, 2023
1 parent 1cbba86 commit d850263
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type AutocompleteAPI =
:> MandatoryQueryParam "radius" Integer
:> MandatoryQueryParam "components" Text
:> MandatoryQueryParam "language" Language
:> QueryParam "origin" LatLong
:> Get '[JSON] GoogleMaps.AutoCompleteResp

type PlaceDetailsAPI =
Expand Down Expand Up @@ -95,7 +96,7 @@ type DirectionsAPI =
:> QueryParam "avoid" Text
:> Get '[JSON] GoogleMaps.DirectionsResp

autoCompleteClient :: Maybe Text -> Text -> Text -> Text -> Integer -> Text -> Language -> EulerClient GoogleMaps.AutoCompleteResp
autoCompleteClient :: Maybe Text -> Text -> Text -> Text -> Integer -> Text -> Language -> Maybe LatLong -> EulerClient GoogleMaps.AutoCompleteResp
getPlaceDetailsClient :: Maybe Text -> Text -> Text -> Text -> EulerClient GoogleMaps.GetPlaceDetailsResp
getPlaceNameClient :: Maybe Text -> Text -> Maybe LatLong -> Maybe Text -> Maybe Language -> EulerClient GoogleMaps.GetPlaceNameResp
distanceMatrixClient ::
Expand Down Expand Up @@ -128,9 +129,10 @@ autoComplete ::
Integer ->
Text ->
Language ->
Maybe LatLong ->
m GoogleMaps.AutoCompleteResp
autoComplete url apiKey input sessiontoken location radius components lang = do
callAPI url (autoCompleteClient sessiontoken apiKey input location radius components lang) "autoComplete" (Proxy :: Proxy GoogleMapsAPI)
autoComplete url apiKey input sessiontoken location radius components lang origin = do
callAPI url (autoCompleteClient sessiontoken apiKey input location radius components lang origin) "autoComplete"
>>= checkGoogleMapsError url

getPlaceDetails ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data AutoCompleteResp = AutoCompleteResp

data Prediction = Prediction
{ description :: Text,
place_id :: Maybe Text
place_id :: Maybe Text,
distance_meters :: Maybe Int
}
deriving (Generic, ToJSON, FromJSON, ToSchema)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ autoComplete cfg AutoCompleteReq {..} = do
let mapsUrl = cfg.googleMapsUrl
key <- decrypt cfg.googleKey
let components = "country:in"
res <- GoogleMaps.autoComplete mapsUrl key input sessionToken location radius components language
let predictions = map (\GoogleMaps.Prediction {..} -> Prediction {placeId = place_id, ..}) res.predictions
res <- GoogleMaps.autoComplete mapsUrl key input sessionToken location radius components language origin
let predictions = map (\GoogleMaps.Prediction {..} -> Prediction {placeId = place_id, distance = distance_meters, ..}) res.predictions
return $ AutoCompleteResp predictions

getPlaceDetails ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ autoSuggest mmiCfg AutoCompleteReq {..} = do
mapsUrl = mmiCfg.mmiNonKeyUrl
token <- MMIAuthToken.getTokenText mmiCfg
res <- MMI.mmiAutoSuggest mapsUrl (Just $ MMITypes.MMIAuthToken token) query loc region lang
let predictions = map (\MMITypes.SuggestedLocations {..} -> Prediction {placeId = Just eLoc, description = placeName <> " " <> placeAddress}) res.suggestedLocations
let predictions = map (\MMITypes.SuggestedLocations {..} -> Prediction {placeId = Just eLoc, description = placeName <> " " <> placeAddress, distance = Nothing}) res.suggestedLocations
return $ AutoCompleteResp predictions

getDistanceMatrix ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ newtype AutoCompleteResp = AutoCompleteResp

data Prediction = Prediction
{ description :: Text,
placeId :: Maybe Text
placeId :: Maybe Text,
distance :: Maybe Int
}
deriving (Generic, ToJSON, FromJSON, ToSchema)

Expand Down

0 comments on commit d850263

Please sign in to comment.