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 vikrantkm1997 committed May 9, 2023
1 parent 591bdc1 commit 27e8d80
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions lib/mobility-core/src/Kernel/External/Maps/Google/MapsClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type AutocompleteAPI =
:> MandatoryQueryParam "radius" Integer
:> MandatoryQueryParam "components" Text
:> MandatoryQueryParam "language" Language
:> QueryParam "strictbounds" Bool
:> QueryParam "origin" LatLong
:> Get '[JSON] GoogleMaps.AutoCompleteResp

type PlaceDetailsAPI =
Expand Down Expand Up @@ -95,7 +97,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 -> Bool -> 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 +130,11 @@ autoComplete ::
Integer ->
Text ->
Language ->
Bool ->
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 strictBounds origin = do
callAPI url (autoCompleteClient sessiontoken apiKey input location radius components lang strictBounds origin) "autoComplete" (Proxy :: Proxy GoogleMapsAPI)
>>= 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 strictbounds 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
7 changes: 5 additions & 2 deletions lib/mobility-core/src/Kernel/External/Maps/Interface/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ data AutoCompleteReq = AutoCompleteReq
sessionToken :: Maybe Text,
location :: Text,
radius :: Integer,
language :: Language
language :: Language,
origin :: Maybe LatLong,
strictbounds :: Maybe Bool
}
deriving stock (Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)
Expand All @@ -144,7 +146,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 27e8d80

Please sign in to comment.