diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/API.hs | 45 | ||||
-rw-r--r-- | spec/thermoprint-spec.cabal | 1 | ||||
-rw-r--r-- | spec/thermoprint-spec.nix | 4 |
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 | ||
17 | import Thermoprint.Printout | 17 | import Thermoprint.Printout |
18 | import Thermoprint.Identifiers | 18 | import Thermoprint.Identifiers |
19 | 19 | ||
20 | import Servant.API | 20 | import Servant.API |
21 | import Data.Aeson | 21 | import Data.Aeson |
22 | 22 | ||
23 | import Data.Set (Set) | 23 | import Data.Set (Set) |
24 | import Data.Map (Map) | 24 | import Data.Map (Map) |
25 | import qualified Data.Map as Map (foldMapWithKey, singleton) | 25 | import qualified Data.Map as Map (foldMapWithKey, singleton) |
26 | import Data.Sequence (Seq) | 26 | import Data.Sequence (Seq) |
27 | 27 | ||
28 | import Data.IntMap.Strict (IntMap) | 28 | import Data.IntMap.Strict (IntMap) |
29 | import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) | 29 | import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) |
30 | 30 | ||
31 | import Data.Text (Text) | 31 | import Data.Text (Text) |
32 | import qualified Data.Text as T | ||
32 | 33 | ||
33 | import Data.Typeable (Typeable) | 34 | import Data.Typeable (Typeable) |
34 | import GHC.Generics (Generic) | 35 | import GHC.Generics (Generic) |
35 | import Control.DeepSeq (NFData) | 36 | import Control.DeepSeq (NFData) |
36 | 37 | ||
37 | import Data.Proxy (Proxy(..)) | 38 | import Data.Proxy (Proxy(..)) |
38 | 39 | ||
39 | import Control.Exception (Exception) | 40 | import Control.Exception (Exception) |
41 | |||
42 | import Data.Time (UTCTime) | ||
43 | import Data.Time.Format | ||
40 | 44 | ||
41 | instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where | 45 | instance (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 | ||
61 | type DraftTitle = Text | 65 | type DraftTitle = Text |
62 | 66 | ||
67 | instance FromText UTCTime where | ||
68 | fromText = parseTimeM True defaultTimeLocale "%s%Q" . T.unpack | ||
69 | |||
70 | instance ToText UTCTime where | ||
71 | toText = T.pack . formatTime defaultTimeLocale "%s%Q" | ||
72 | |||
63 | type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) | 73 | type 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 | }: |
5 | mkDerivation { | 5 | mkDerivation { |
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 |