From 44a6279b86deecc865f05d2ee519f64f39ac1ccb Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 31 Jan 2016 15:03:57 +0000 Subject: Recording job creation time in printer queues --- spec/src/Thermoprint/API.hs | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'spec/src/Thermoprint/API.hs') diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index e3d4b61..4f9d074 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs @@ -14,29 +14,33 @@ module Thermoprint.API , module Thermoprint.Printout ) where -import Thermoprint.Printout -import Thermoprint.Identifiers +import Thermoprint.Printout +import Thermoprint.Identifiers -import Servant.API -import Data.Aeson +import Servant.API +import Data.Aeson -import Data.Set (Set) -import Data.Map (Map) +import Data.Set (Set) +import Data.Map (Map) import qualified Data.Map as Map (foldMapWithKey, singleton) -import Data.Sequence (Seq) +import Data.Sequence (Seq) -import Data.IntMap.Strict (IntMap) +import Data.IntMap.Strict (IntMap) import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) -import Data.Text (Text) +import Data.Text (Text) +import qualified Data.Text as T -import Data.Typeable (Typeable) -import GHC.Generics (Generic) -import Control.DeepSeq (NFData) +import Data.Typeable (Typeable) +import GHC.Generics (Generic) +import Control.DeepSeq (NFData) -import Data.Proxy (Proxy(..)) +import Data.Proxy (Proxy(..)) -import Control.Exception (Exception) +import Control.Exception (Exception) + +import Data.Time (UTCTime) +import Data.Time.Format instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) @@ -60,9 +64,20 @@ data PrintingError = UnknownError type DraftTitle = Text +instance FromText UTCTime where + fromText = parseTimeM True defaultTimeLocale "%s%Q" . T.unpack + +instance ToText UTCTime where + toText = T.pack . formatTime defaultTimeLocale "%s%Q" + type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) :<|> "jobs" :> ( - QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq (JobId, JobStatus)) + QueryParam "printer" PrinterId + :> QueryParam "min" JobId + :> QueryParam "max" JobId + :> QueryParam "minTime" UTCTime + :> QueryParam "maxTime" UTCTime + :> Get '[JSON] (Seq (JobId, UTCTime, JobStatus)) :<|> QueryParam "printer" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId ) :<|> "job" :> Capture "jobId" JobId :> ( -- cgit v1.2.3