diff options
Diffstat (limited to 'spec/src')
| -rw-r--r-- | spec/src/Thermoprint/API.hs | 45 | 
1 files changed, 30 insertions, 15 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 :> ( | 
