summaryrefslogtreecommitdiff
path: root/Model.hs
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2014-12-03 18:40:57 +0100
committerFélix Sipma <felix.sipma@no-log.org>2014-12-03 18:40:57 +0100
commit6632065a5f13cb2296007eb78085f777d9702022 (patch)
tree87897ad1cd81210df1a6bc74796662d6e6340ff6 /Model.hs
parent9cad9cb6f89d1e839abaf3334e7e39191a4a3fd6 (diff)
PlaceListR json
Diffstat (limited to 'Model.hs')
-rw-r--r--Model.hs30
1 files changed, 22 insertions, 8 deletions
diff --git a/Model.hs b/Model.hs
index 20a33f4..9bf554c 100644
--- a/Model.hs
+++ b/Model.hs
@@ -37,12 +37,26 @@ instance FromJSON Shop where
parseJSON _ = mzero
+toGeoFeature :: Entity Place -> G.GeoFeature Value
+toGeoFeature (Entity pid p) = G.GeoFeature
+ Nothing
+ (G.Point $ G.GeoPoint pointpos)
+ (object
+ [ "id" .= (String $ toPathPiece pid)
+ , "ident" .= (String $ placeIdent p)
+ ])
+ Nothing
+ where
+ pointpos =
+ [ pntLat $ placeLocation p
+ , pntLon $ placeLocation p
+ ]
+
instance ToJSON (Entity Place) where
- toJSON (Entity pid p) = toJSON $ G.GeoFeature
- Nothing
- (G.Point $ G.GeoPoint [pntLat $ placeLocation p, pntLon $ placeLocation p])
- (object
- [ "id" .= (String $ toPathPiece pid)
- , "ident" .= (String $ placeIdent p)
- ])
- Nothing
+ toJSON = toJSON . toGeoFeature
+
+toGeoFeatureCollection :: [Entity Place] -> G.GeoFeatureCollection Value
+toGeoFeatureCollection l = G.GeoFeatureCollection Nothing $ map toGeoFeature l
+
+instance ToJSON [Entity Place] where
+ toJSON = toJSON . toGeoFeatureCollection