From 1fed9563fd75e6528740471f04746138284257b3 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 16 Feb 2022 15:32:57 +0100 Subject: internal state: sort according to org (also, more lenses i guess) --- server/Handlers.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'server/Handlers.hs') diff --git a/server/Handlers.hs b/server/Handlers.hs index cb714d9..a4ddab4 100644 --- a/server/Handlers.hs +++ b/server/Handlers.hs @@ -8,7 +8,7 @@ module Handlers ( -- , relintImpl , adminOverviewImpl , AdminOverview(..) - ) where + ,MapService(..)) where import Universum @@ -18,7 +18,7 @@ import qualified Data.Aeson as A import qualified Data.Map as M import Servant (Handler, err404, throwError) import Server (JobStatus (..), ServerState, Sha1, - unState) + getJobStatus, unState) -- | annoying (and afaik unused), but has to be here for type system reasons -- instance MonadFail Handler where @@ -48,23 +48,24 @@ import Server (JobStatus (..), ServerState, Sha1, -- pure NoContent -- | an info type wrapped around the server state, to carry serialisation instances. --- TODO: should probably not be defined here newtype AdminOverview = AdminOverview { unAdminOverview :: ServerState } +newtype MapService = + MapService { unMapService :: ServerState } + instance ToJSON AdminOverview where toJSON (AdminOverview state) = - toJSON $ view unState state <&> \(ref, status) -> + toJSON $ view unState state <&> \org -> flip map org $ \(ref, status) -> A.object [ "remote" .= ref , "status" .= status ] -statusImpl :: MVar ServerState -> Sha1 -> Handler JobStatus -statusImpl state sha1 = do - status <- liftIO $ withMVar state $ \state -> - pure $ M.lookup sha1 (map snd $ view unState state) +statusImpl :: MVar ServerState -> Text -> Sha1 -> Handler JobStatus +statusImpl state orgslug sha1 = do + status <- liftIO $ getJobStatus state orgslug sha1 case status of - Just res -> pure res + Just res -> pure $ snd res Nothing -> throwError err404 -- cgit v1.2.3