diff options
Diffstat (limited to 'spec/src')
| -rw-r--r-- | spec/src/Thermoprint/API.hs | 69 | ||||
| -rw-r--r-- | spec/src/Thermoprint/Identifiers.hs | 19 |
2 files changed, 80 insertions, 8 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index f2ffd02..d722903 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs | |||
| @@ -1,21 +1,74 @@ | |||
| 1 | {-# LANGUAGE GeneralizedNewtypeDeriving, NoDeriveAnyClass #-} | 1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} |
| 2 | {-# LANGUAGE TypeOperators, DataKinds #-} | 2 | {-# LANGUAGE TypeOperators, DataKinds #-} |
| 3 | {-# LANGUAGE OverloadedStrings #-} | ||
| 3 | 4 | ||
| 4 | module Thermoprint.API | 5 | module Thermoprint.API |
| 5 | ( PrinterId(..) | 6 | ( PrinterStatus(..) |
| 6 | , JobId(..) | 7 | , JobStatus(..) |
| 7 | , ThermoprintAPI | 8 | , ThermoprintAPI |
| 9 | , thermoprintAPI | ||
| 10 | , module Thermoprint.Identifiers | ||
| 11 | , module Thermoprint.Printout | ||
| 8 | ) where | 12 | ) where |
| 9 | 13 | ||
| 10 | import Thermoprint.Printout | 14 | import Thermoprint.Printout |
| 15 | import Thermoprint.Identifiers | ||
| 11 | 16 | ||
| 12 | import Servant.API | 17 | import Servant.API |
| 18 | import Servant.Docs | ||
| 13 | import Data.Aeson | 19 | import Data.Aeson |
| 14 | 20 | ||
| 15 | newtype PrinterId = PrinterId Integer | 21 | import Data.Set (Set) |
| 16 | deriving (Show, Eq, FromText, ToText, FromJSON, ToJSON) | 22 | import Data.Sequence (Seq) |
| 17 | 23 | ||
| 18 | newtype JobId = JobId Integer | 24 | import GHC.Generics (Generic) |
| 19 | deriving (Show, Eq, FromText, ToText, FromJSON, ToJSON) | ||
| 20 | 25 | ||
| 21 | type ThermoprintAPI = "print" :> Capture "printerId" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId | 26 | import Data.Proxy (Proxy(..)) |
| 27 | |||
| 28 | import Data.Functor.Identity (Identity(..)) | ||
| 29 | import Control.Exception (Exception) | ||
| 30 | import Data.Typeable (Typeable) | ||
| 31 | |||
| 32 | data PrinterStatus = Busy JobId | ||
| 33 | | Available | ||
| 34 | deriving (Generic, Show, FromJSON, ToJSON) | ||
| 35 | |||
| 36 | data JobInfo = JobInfo | ||
| 37 | { jobPrinter :: PrinterId | ||
| 38 | , jobStatus :: JobStatus | ||
| 39 | } | ||
| 40 | |||
| 41 | data JobStatus = Queued | ||
| 42 | | Printing | ||
| 43 | | Done | ||
| 44 | | Failed PrintingError | ||
| 45 | deriving (Generic, Show, FromJSON, ToJSON) | ||
| 46 | |||
| 47 | data PrintingError = UnknownError | ||
| 48 | deriving (Typeable, Generic, Show, FromJSON, ToJSON, Exception) | ||
| 49 | |||
| 50 | type ThermoprintAPI = "printers" :> Get '[JSON] (Set PrinterId) | ||
| 51 | :<|> "printer" :> Capture "printerId" PrinterId :> ( | ||
| 52 | ReqBody '[JSON] Printout :> Post '[JSON] JobId | ||
| 53 | :<|> "status" :> Get '[JSON] PrinterStatus | ||
| 54 | ) | ||
| 55 | :<|> "jobs" :> ( | ||
| 56 | QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq JobId) | ||
| 57 | ) | ||
| 58 | :<|> "job" :> Capture "jobId" JobId :> ( | ||
| 59 | Get '[JSON] Printout | ||
| 60 | :<|> "status" :> Get '[JSON] JobInfo | ||
| 61 | :<|> Delete '[] () | ||
| 62 | ) | ||
| 63 | :<|> "drafts" :> ( | ||
| 64 | Get '[JSON] (Set DraftId) | ||
| 65 | :<|> ReqBody '[JSON] Printout :> Post '[JSON] DraftId | ||
| 66 | ) | ||
| 67 | :<|> "draft" :> Capture "draftId" DraftId :> ( | ||
| 68 | ReqBody '[JSON] Printout :> Put '[] () | ||
| 69 | :<|> Get '[JSON] Printout | ||
| 70 | :<|> Delete '[] () | ||
| 71 | ) | ||
| 72 | |||
| 73 | thermoprintAPI :: Proxy ThermoprintAPI | ||
| 74 | thermoprintAPI = Proxy | ||
diff --git a/spec/src/Thermoprint/Identifiers.hs b/spec/src/Thermoprint/Identifiers.hs new file mode 100644 index 0000000..bd0b7a6 --- /dev/null +++ b/spec/src/Thermoprint/Identifiers.hs | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | {-# LANGUAGE GeneralizedNewtypeDeriving, NoDeriveAnyClass #-} | ||
| 2 | |||
| 3 | module Thermoprint.Identifiers | ||
| 4 | ( PrinterId(..) | ||
| 5 | , JobId(..) | ||
| 6 | , DraftId(..) | ||
| 7 | ) where | ||
| 8 | |||
| 9 | import Servant.API (ToText, FromText) | ||
| 10 | import Data.Aeson (FromJSON, ToJSON) | ||
| 11 | |||
| 12 | newtype PrinterId = PrinterId Integer | ||
| 13 | deriving (Show, Eq, Ord, Enum, FromText, ToText, FromJSON, ToJSON) | ||
| 14 | |||
| 15 | newtype JobId = JobId Integer | ||
| 16 | deriving (Show, Eq, Ord, Enum, FromText, ToText, FromJSON, ToJSON) | ||
| 17 | |||
| 18 | newtype DraftId = DraftId Integer | ||
| 19 | deriving (Show, Eq, Ord, Enum, FromText, ToText, FromJSON, ToJSON) | ||
