From a805783f4bb2868e63ba49a911775fff30df5a07 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 18 Feb 2016 15:04:19 +0100 Subject: Introduced Range --- server/src/Thermoprint/Server/API.hs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'server/src') diff --git a/server/src/Thermoprint/Server/API.hs b/server/src/Thermoprint/Server/API.hs index cd4326e..3f3ab46 100644 --- a/server/src/Thermoprint/Server/API.hs +++ b/server/src/Thermoprint/Server/API.hs @@ -141,16 +141,13 @@ printerStatus = fmap queueToStatus . queue' . snd <=< lookupPrinter . Just queueToStatus (Queue _ (Just c) _) = Busy . castId $ jobId c listJobs :: Maybe PrinterId - -> Maybe API.JobId -> Maybe API.JobId - -> Maybe UTCTime -> Maybe UTCTime + -> Maybe (Range API.JobId) -> Maybe (Range UTCTime) -> Handler (Seq (API.JobId, UTCTime, JobStatus)) -listJobs Nothing minId maxId minTime maxTime = fmap mconcat . mapM (\pId -> listJobs (Just pId) minId maxId minTime maxTime) =<< asks (Map.keys . printers) -listJobs pId minId maxId minTime maxTime = fmap (filterJobs . extractJobs) . (\(a, b) -> (,) a <$> queue' b) =<< lookupPrinter pId +listJobs Nothing idR timeR = fmap mconcat . mapM (\pId -> listJobs (Just pId) idR timeR) =<< asks (Map.keys . printers) +listJobs pId idR timeR = fmap (filterJobs . extractJobs) . (\(a, b) -> (,) a <$> queue' b) =<< lookupPrinter pId where - filterJobs = Seq.filter (\(id, time, _) -> and ([ maybe True (<= id ) minId - , maybe True (>= id ) maxId - , maybe True (<= time) minTime - , maybe True (>= time) maxTime + filterJobs = Seq.filter (\(id, time, _) -> and ([ maybe True (`contains` id) idR + , maybe True (`contains` time) timeR ] :: [Bool]) ) @@ -158,7 +155,7 @@ getJob :: API.JobId -> Handler Printout getJob jobId = fmap jobContent . maybe (left err404) return =<< runSqlPool (get $ castId jobId) =<< asks sqlPool jobStatus :: API.JobId -> Handler JobStatus -jobStatus jobId = maybe (left err404) return . lookup jobId . map (\(id, _, st) -> (id, st)) . toList =<< listJobs Nothing Nothing Nothing Nothing Nothing +jobStatus jobId = maybe (left err404) return . lookup jobId . map (\(id, _, st) -> (id, st)) . toList =<< listJobs Nothing Nothing Nothing abortJob :: API.JobId -> Handler () abortJob needle = do -- cgit v1.2.3