summaryrefslogtreecommitdiff
path: root/Model.hs
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2014-12-03 11:48:39 +0100
committerFélix Sipma <felix.sipma@no-log.org>2014-12-03 11:49:08 +0100
commite90e863c390dd6b63ba5fadc328b95afa3475355 (patch)
treeecb2b1073e4ee416de244ec850754becb45c77a9 /Model.hs
parent196395e9026f80f98aeb9983d787aa4f92eedd4c (diff)
geojson
Diffstat (limited to 'Model.hs')
-rw-r--r--Model.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/Model.hs b/Model.hs
index bc963f7..20a33f4 100644
--- a/Model.hs
+++ b/Model.hs
@@ -6,8 +6,9 @@ import Database.Persist.Quasi
import Shop.Unit.Types (Unit)
import Shop.Amount.Types (Amount)
import Shop.Quantity.Types (Quantity)
-import Shop.Place.Types (Point)
+import Shop.Place.Types (Point (..))
import Data.Aeson ((.:?))
+import qualified Data.Geospatial as G
-- You can define all of your database entities in the entities file.
-- You can find more information on persistent and how to declare entities
@@ -35,3 +36,13 @@ instance FromJSON Shop where
<*> o .: "updated"
parseJSON _ = mzero
+
+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