aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-31 15:03:57 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-31 15:03:57 +0000
commit44a6279b86deecc865f05d2ee519f64f39ac1ccb (patch)
treee2634312eee0c99b383520e0877c33ece32102ee /spec
parent2914fd9d66265080dbb38aed61ef8aad77b5ec2c (diff)
downloadthermoprint-44a6279b86deecc865f05d2ee519f64f39ac1ccb.tar
thermoprint-44a6279b86deecc865f05d2ee519f64f39ac1ccb.tar.gz
thermoprint-44a6279b86deecc865f05d2ee519f64f39ac1ccb.tar.bz2
thermoprint-44a6279b86deecc865f05d2ee519f64f39ac1ccb.tar.xz
thermoprint-44a6279b86deecc865f05d2ee519f64f39ac1ccb.zip
Recording job creation time in printer queues
Diffstat (limited to 'spec')
-rw-r--r--spec/src/Thermoprint/API.hs45
-rw-r--r--spec/thermoprint-spec.cabal1
-rw-r--r--spec/thermoprint-spec.nix4
3 files changed, 33 insertions, 17 deletions
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
14 , module Thermoprint.Printout 14 , module Thermoprint.Printout
15 ) where 15 ) where
16 16
17import Thermoprint.Printout 17import Thermoprint.Printout
18import Thermoprint.Identifiers 18import Thermoprint.Identifiers
19 19
20import Servant.API 20import Servant.API
21import Data.Aeson 21import Data.Aeson
22 22
23import Data.Set (Set) 23import Data.Set (Set)
24import Data.Map (Map) 24import Data.Map (Map)
25import qualified Data.Map as Map (foldMapWithKey, singleton) 25import qualified Data.Map as Map (foldMapWithKey, singleton)
26import Data.Sequence (Seq) 26import Data.Sequence (Seq)
27 27
28import Data.IntMap.Strict (IntMap) 28import Data.IntMap.Strict (IntMap)
29import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) 29import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton)
30 30
31import Data.Text (Text) 31import Data.Text (Text)
32import qualified Data.Text as T
32 33
33import Data.Typeable (Typeable) 34import Data.Typeable (Typeable)
34import GHC.Generics (Generic) 35import GHC.Generics (Generic)
35import Control.DeepSeq (NFData) 36import Control.DeepSeq (NFData)
36 37
37import Data.Proxy (Proxy(..)) 38import Data.Proxy (Proxy(..))
38 39
39import Control.Exception (Exception) 40import Control.Exception (Exception)
41
42import Data.Time (UTCTime)
43import Data.Time.Format
40 44
41instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where 45instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where
42 toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) 46 toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId)
@@ -60,9 +64,20 @@ data PrintingError = UnknownError
60 64
61type DraftTitle = Text 65type DraftTitle = Text
62 66
67instance FromText UTCTime where
68 fromText = parseTimeM True defaultTimeLocale "%s%Q" . T.unpack
69
70instance ToText UTCTime where
71 toText = T.pack . formatTime defaultTimeLocale "%s%Q"
72
63type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) 73type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus)
64 :<|> "jobs" :> ( 74 :<|> "jobs" :> (
65 QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq (JobId, JobStatus)) 75 QueryParam "printer" PrinterId
76 :> QueryParam "min" JobId
77 :> QueryParam "max" JobId
78 :> QueryParam "minTime" UTCTime
79 :> QueryParam "maxTime" UTCTime
80 :> Get '[JSON] (Seq (JobId, UTCTime, JobStatus))
66 :<|> QueryParam "printer" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId 81 :<|> QueryParam "printer" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId
67 ) 82 )
68 :<|> "job" :> Capture "jobId" JobId :> ( 83 :<|> "job" :> Capture "jobId" JobId :> (
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal
index da79ee8..7446da3 100644
--- a/spec/thermoprint-spec.cabal
+++ b/spec/thermoprint-spec.cabal
@@ -44,6 +44,7 @@ library
44 , aeson >=0.9.0 && <1 44 , aeson >=0.9.0 && <1
45 , base64-bytestring >=1.0.0 && <2 45 , base64-bytestring >=1.0.0 && <2
46 , encoding >=0.8 && <1 46 , encoding >=0.8 && <1
47 , time >=1.5.0 && <2
47 -- hs-source-dirs: 48 -- hs-source-dirs:
48 default-language: Haskell2010 49 default-language: Haskell2010
49 50
diff --git a/spec/thermoprint-spec.nix b/spec/thermoprint-spec.nix
index 1825ddd..b67273a 100644
--- a/spec/thermoprint-spec.nix
+++ b/spec/thermoprint-spec.nix
@@ -1,6 +1,6 @@
1{ mkDerivation, aeson, base, base64-bytestring, bytestring, Cabal 1{ mkDerivation, aeson, base, base64-bytestring, bytestring, Cabal
2, cabal-test-quickcheck, containers, deepseq, encoding, hspec 2, cabal-test-quickcheck, containers, deepseq, encoding, hspec
3, QuickCheck, quickcheck-instances, servant, stdenv, text 3, QuickCheck, quickcheck-instances, servant, stdenv, text, time
4}: 4}:
5mkDerivation { 5mkDerivation {
6 pname = "thermoprint-spec"; 6 pname = "thermoprint-spec";
@@ -9,7 +9,7 @@ mkDerivation {
9 libraryHaskellDepends = [ 9 libraryHaskellDepends = [
10 aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck 10 aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck
11 containers deepseq encoding QuickCheck quickcheck-instances servant 11 containers deepseq encoding QuickCheck quickcheck-instances servant
12 text 12 text time
13 ]; 13 ];
14 testHaskellDepends = [ 14 testHaskellDepends = [
15 aeson base hspec QuickCheck quickcheck-instances 15 aeson base hspec QuickCheck quickcheck-instances