From 7bd1c116c26d0c2147aa787b04f6e7de85d44133 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 11 Jul 2023 21:55:55 +0200 Subject: [haskell] Implemented pagination and systems list api call --- haskell/src/SpaceTraders/Model/System.hs | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 haskell/src/SpaceTraders/Model/System.hs (limited to 'haskell/src/SpaceTraders/Model/System.hs') diff --git a/haskell/src/SpaceTraders/Model/System.hs b/haskell/src/SpaceTraders/Model/System.hs new file mode 100644 index 0000000..dacd27a --- /dev/null +++ b/haskell/src/SpaceTraders/Model/System.hs @@ -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 ) -- cgit v1.2.3