blob: 959edff6252acff9dd4d50ea0f1a93660df3a207 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 )
|