diff options
author | Julien Dessaux | 2023-07-18 00:02:33 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-07-18 00:02:33 +0200 |
commit | 4af96da5670566c111fa5c7dac9572eaac021a4b (patch) | |
tree | 74ae00fb63e087437bc3a62152d4b7fecf8c039e /haskell/src/SpaceTraders/APIClient/Systems.hs | |
parent | [haskell] Trigger a program restart when the api client encounters a server r... (diff) | |
download | spacetraders-4af96da5670566c111fa5c7dac9572eaac021a4b.tar.gz spacetraders-4af96da5670566c111fa5c7dac9572eaac021a4b.tar.bz2 spacetraders-4af96da5670566c111fa5c7dac9572eaac021a4b.zip |
[haskell] Refactored everything with a ReaderT pattern
Diffstat (limited to '')
-rw-r--r-- | haskell/src/SpaceTraders/APIClient/Systems.hs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/haskell/src/SpaceTraders/APIClient/Systems.hs b/haskell/src/SpaceTraders/APIClient/Systems.hs index fca2037..2e275ee 100644 --- a/haskell/src/SpaceTraders/APIClient/Systems.hs +++ b/haskell/src/SpaceTraders/APIClient/Systems.hs @@ -7,28 +7,26 @@ module SpaceTraders.APIClient.Systems ) where import Control.Exception -import qualified Data.Text as T -import qualified Database.SQLite.Simple as S import Network.HTTP.Simple +import SpaceTraders import SpaceTraders.APIClient.Client import SpaceTraders.APIClient.Pagination import SpaceTraders.Database.Systems import SpaceTraders.Model.System(System) -listSystems :: T.Text -> S.Connection -> IO (APIResponse [System]) -listSystems t conn = do - s <- getSystems conn +listSystems :: SpaceTradersT (APIResponse [System]) +listSystems = do + s <- getSystems listSystems' Pagination{limit=20, page=((length s) `div` 20) + 1, total=0} where - listSystems' :: Pagination -> IO (APIResponse [System]) + listSystems' :: Pagination -> SpaceTradersT (APIResponse [System]) listSystems' p = do - resp <- sendPaginated $ setRequestPath "/v2/systems" - $ paginatedReq t (Just p) + resp <- sendPaginated (Just p) $ setRequestPath "/v2/systems" case resp of - Left e -> throwIO e - Right (APIMessage [] _) -> Right <$> getSystems conn + Left e -> throw e + Right (APIMessage [] _) -> Right <$> getSystems Right (APIMessage r (Just p')) -> do - addSystems conn r + addSystems r listSystems' (nextPage p') _ -> undefined |