Skip to content

Commit

Permalink
Add top-level task ID listing endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
memowe committed Feb 23, 2024
1 parent 10d5dcd commit 1555f16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/LiBro/WebService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import LiBro.Control
import LiBro.Data
import qualified Data.Map as M
import Data.Map ((!))
import Data.Tree
import Data.Aeson
import Data.Proxy
import Servant
import Control.Monad.Reader
import GHC.Generics

newtype PersonIDs = PersonIDs {personIDs :: [Int]} deriving Generic
newtype PersonIDs = PersonIDs {personIDs :: [Int]} deriving Generic
newtype TaskIDs = TaskIDs {taskIDs :: [Int]} deriving Generic
instance ToJSON PersonIDs
instance ToJSON TaskIDs

type LiBroHandler = ReaderT LiBroState Handler

Expand All @@ -20,10 +23,12 @@ runAction action = ask >>= liftIO . runReaderT action

type LiBroAPI = "person" :> Get '[JSON] PersonIDs
:<|> "person" :> Capture "pid" Int :> Get '[JSON] Person
:<|> "task" :> Get '[JSON] TaskIDs

libroServer :: ServerT LiBroAPI LiBroHandler
libroServer = hPersonIDs
:<|> hPersonDetails
:<|> hTaskIDs
where
hPersonIDs :: LiBroHandler PersonIDs
hPersonIDs = do
Expand All @@ -35,6 +40,11 @@ libroServer = hPersonIDs
ps <- persons <$> runAction lsData
return $ ps ! pId

hTaskIDs :: LiBroHandler TaskIDs
hTaskIDs = do
ts <- tasks <$> runAction lsData
return $ TaskIDs (tid . rootLabel <$> ts)

libroApi :: Proxy LiBroAPI
libroApi = Proxy

Expand Down
6 changes: 6 additions & 0 deletions test/LiBro/WebServiceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ listings = describe "Simple data listing endpoints" $ with lws $ do
[json|{"pid": 2, "name": "Baz Quux", "email": "[email protected]"}|]
{matchStatus = 200}

describe "Task ID listing endpoint" $ do
it "Respond with correct IDs" $ do
get "/task" `shouldRespondWith`
[json|{"taskIDs": [17]}|]
{matchStatus = 200}

where lws = libro <$> initLiBroState cfg
cfg = Config (def {directory = "test/storage-files/data"}) def

0 comments on commit 1555f16

Please sign in to comment.