[haskell] Implemented pagination and systems list api call
This commit is contained in:
parent
8249bf432a
commit
7bd1c116c2
9 changed files with 186 additions and 8 deletions
37
haskell/src/SpaceTraders/Model/System.hs
Normal file
37
haskell/src/SpaceTraders/Model/System.hs
Normal file
|
@ -0,0 +1,37 @@
|
|||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module SpaceTraders.Model.System
|
||||
( System(..)
|
||||
) where
|
||||
|
||||
import Data.Aeson
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics
|
||||
|
||||
import SpaceTraders.Model.Waypoint(Waypoint)
|
||||
|
||||
data System = System { sectorSymbol :: T.Text
|
||||
, symbol :: T.Text
|
||||
, systemType :: T.Text
|
||||
, x :: Int
|
||||
, y :: Int
|
||||
, waypoints :: [Waypoint]
|
||||
--, factions :: [Faction]
|
||||
} deriving (Generic, Show)
|
||||
instance FromJSON System where
|
||||
parseJSON = withObject "System" $ \o ->
|
||||
System <$> o .: "sectorSymbol"
|
||||
<*> o .: "symbol"
|
||||
<*> o .: "type"
|
||||
<*> o .: "x"
|
||||
<*> o .: "y"
|
||||
<*> o .: "waypoints"
|
||||
instance ToJSON System where
|
||||
toEncoding (System ss s t xx yy w) = pairs ( "sectorSymbol" .= ss
|
||||
<> "symbol" .= s
|
||||
<> "type" .= t
|
||||
<> "x" .= xx
|
||||
<> "y" .= yy
|
||||
<> "waypoints" .= w )
|
28
haskell/src/SpaceTraders/Model/Waypoint.hs
Normal file
28
haskell/src/SpaceTraders/Model/Waypoint.hs
Normal file
|
@ -0,0 +1,28 @@
|
|||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module SpaceTraders.Model.Waypoint
|
||||
( Waypoint(..)
|
||||
) where
|
||||
|
||||
import Data.Aeson
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics
|
||||
|
||||
data Waypoint = Waypoint { symbol :: T.Text
|
||||
, waypointType :: T.Text
|
||||
, x :: Int
|
||||
, y :: Int
|
||||
} deriving (Generic, Show)
|
||||
instance FromJSON Waypoint where
|
||||
parseJSON = withObject "Waypoint" $ \o ->
|
||||
Waypoint <$> o .: "symbol"
|
||||
<*> o .: "type"
|
||||
<*> o .: "x"
|
||||
<*> o .: "y"
|
||||
instance ToJSON Waypoint where
|
||||
toEncoding (Waypoint s t xx yy) = pairs ( "symbol" .= s
|
||||
<> "type" .= t
|
||||
<> "x" .= xx
|
||||
<> "y" .= yy )
|
Loading…
Add table
Add a link
Reference in a new issue