summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/Route.hs
diff options
context:
space:
mode:
Diffstat (limited to 'haskell/src/SpaceTraders/Model/Route.hs')
-rw-r--r--haskell/src/SpaceTraders/Model/Route.hs40
1 files changed, 40 insertions, 0 deletions
diff --git a/haskell/src/SpaceTraders/Model/Route.hs b/haskell/src/SpaceTraders/Model/Route.hs
new file mode 100644
index 0000000..959edff
--- /dev/null
+++ b/haskell/src/SpaceTraders/Model/Route.hs
@@ -0,0 +1,40 @@
+{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE OverloadedStrings #-}
+
+module SpaceTraders.Model.Route
+ ( Route(..)
+ , RouteEndpoint(..)
+ ) where
+
+import Control.Monad
+import Data.Aeson
+import Data.Time
+import GHC.Generics
+import qualified Data.Text as T
+
+data Route = Route { arrival :: UTCTime
+ , departure :: RouteEndpoint
+ , departureTime :: UTCTime
+ , destination :: RouteEndpoint
+ } deriving (FromJSON, Generic, Show, ToJSON)
+
+data RouteEndpoint = RouteEndpoint { routeEndpointType :: T.Text
+ , symbol :: T.Text
+ , systemSymbol :: T.Text
+ , x :: Int
+ , y :: Int
+ } deriving (Generic, Show)
+instance FromJSON RouteEndpoint where
+ parseJSON (Object o) = RouteEndpoint <$> o .: "type"
+ <*> o .: "symbol"
+ <*> o .: "systemSymbol"
+ <*> o .: "x"
+ <*> o .: "y"
+ parseJSON _ = mzero
+instance ToJSON RouteEndpoint where
+ toEncoding (RouteEndpoint t s ss xx yy) = pairs ( "type" .= t
+ <> "symbol" .= s
+ <> "systemSymbol" .= ss
+ <> "x" .= xx
+ <> "y" .= yy )