-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend/feat : #70 OSM Reverse Geocode API Integration
- Loading branch information
janhavi.soni
committed
Apr 7, 2023
1 parent
ff1acd8
commit 8c6138a
Showing
8 changed files
with
222 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
lib/mobility-core/src/Kernel/External/Maps/Interface/OSM.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{- | ||
Copyright 2022-23, Juspay India Pvt Ltd | ||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License | ||
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is | ||
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero | ||
General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
-} | ||
|
||
module Kernel.External.Maps.Interface.OSM where | ||
|
||
import Kernel.External.Maps.Interface.Types | ||
import Kernel.External.Maps.OSM.Config | ||
import qualified Kernel.External.Maps.OSM.ReverseGeocode as OSM | ||
import Kernel.Prelude | ||
import Kernel.Tools.Metrics.CoreMetrics (CoreMetrics) | ||
import Kernel.Types.App | ||
|
||
getPlaceDetailsFromLatLon :: | ||
( CoreMetrics m, | ||
MonadFlow m | ||
) => | ||
OSMCfg -> | ||
GetPlaceDetailsFromLatLonReq -> | ||
m GetPlaceDetailsFromLatLonResp | ||
getPlaceDetailsFromLatLon osmCfg req = do | ||
reverseGeocodeRes <- OSM.getPlaceDetailsFromLatLon osmCfg.osmUrl req.responseFormat req.location.lat req.location.lon | ||
return | ||
GetPlaceDetailsFromLatLonResp | ||
{ placeId = reverseGeocodeRes.place_id, | ||
displayName = reverseGeocodeRes.display_name, | ||
address = | ||
PlaceDetails | ||
{ city = reverseGeocodeRes.address.state_district, | ||
state_ = reverseGeocodeRes.address.state, | ||
country = reverseGeocodeRes.address.country, | ||
street = reverseGeocodeRes.address.road, | ||
building = Nothing, | ||
areaCode = reverseGeocodeRes.address.postcode, | ||
area = reverseGeocodeRes.address.neighbourhood | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{- | ||
Copyright 2022-23, Juspay India Pvt Ltd | ||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License | ||
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is | ||
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero | ||
General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
-} | ||
|
||
module Kernel.External.Maps.OSM.Config where | ||
|
||
import Kernel.Prelude | ||
|
||
data OSMCfg = OSRMCfg | ||
{ osmUrl :: BaseUrl | ||
} | ||
deriving (Show, Eq, Generic, FromJSON, ToJSON) |
38 changes: 38 additions & 0 deletions
38
lib/mobility-core/src/Kernel/External/Maps/OSM/MapsClient/Types.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{- | ||
Copyright 2022-23, Juspay India Pvt Ltd | ||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License | ||
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is | ||
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero | ||
General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
-} | ||
{-# LANGUAGE DerivingVia #-} | ||
|
||
module Kernel.External.Maps.OSM.MapsClient.Types where | ||
|
||
import Kernel.Prelude | ||
|
||
data ReverseGeocodeRes = ReverseGeocodeRes | ||
{ place_id :: Text, | ||
lat :: Double, | ||
lon :: Double, | ||
display_name :: Text, | ||
address :: AddressInfo | ||
} | ||
deriving (Generic, ToJSON, FromJSON, ToSchema) | ||
|
||
data AddressInfo = AddressInfo | ||
{ road :: Text, | ||
neighbourhood :: Text, | ||
state_district :: Text, | ||
state :: Text, | ||
postcode :: Text, | ||
country :: Text, | ||
country_code :: Maybe Text | ||
} | ||
deriving (Generic, ToJSON, FromJSON, ToSchema) |
50 changes: 50 additions & 0 deletions
50
lib/mobility-core/src/Kernel/External/Maps/OSM/ReverseGeocode.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{- | ||
Copyright 2022-23, Juspay India Pvt Ltd | ||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License | ||
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is | ||
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero | ||
General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
-} | ||
|
||
module Kernel.External.Maps.OSM.ReverseGeocode where | ||
|
||
import EulerHS.Types (EulerClient, client) | ||
import Kernel.External.Maps.OSM.MapsClient.Types as OSM | ||
import Kernel.Prelude | ||
import Kernel.Tools.Metrics.CoreMetrics (CoreMetrics) | ||
import Kernel.Types.Common | ||
import Kernel.Types.Error | ||
import Kernel.Utils.Common | ||
import Servant hiding (throwError) | ||
|
||
type OSMReverseGeocodeAPI = | ||
"reverse" | ||
:> MandatoryQueryParam "format" Text | ||
:> MandatoryQueryParam "lat" Double | ||
:> MandatoryQueryParam "lon" Double | ||
:> Get '[JSON] OSM.ReverseGeocodeRes | ||
|
||
osmReverseGeocodeAPI :: Proxy OSMReverseGeocodeAPI | ||
osmReverseGeocodeAPI = Proxy | ||
|
||
getPlaceDetailsFromLatLonClient :: Text -> Double -> Double -> EulerClient OSM.ReverseGeocodeRes | ||
getPlaceDetailsFromLatLonClient = client osmReverseGeocodeAPI | ||
|
||
getPlaceDetailsFromLatLon :: | ||
( CoreMetrics m, | ||
MonadFlow m | ||
) => | ||
BaseUrl -> | ||
Text -> | ||
Double -> | ||
Double -> | ||
m OSM.ReverseGeocodeRes | ||
getPlaceDetailsFromLatLon osmUrl format latitude longitude = do | ||
callAPI osmUrl (getPlaceDetailsFromLatLonClient format latitude longitude) "osm-getPlaceDetails" | ||
>>= fromEitherM (\err -> InternalError $ "Failed to call OSM Reverse Geocode API" <> show err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters