From 79a01c5fe636dad60338e4847be8b3cbf3716192 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 21 Jan 2016 08:43:56 +0000 Subject: Reworked API --- spec/src/Thermoprint/API.hs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'spec/src/Thermoprint/API.hs') diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 627f9b1..4b10130 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs @@ -7,6 +7,7 @@ module Thermoprint.API ( PrinterStatus(..) , JobStatus(..) , PrintingError(..) + , DraftTitle , ThermoprintAPI , thermoprintAPI , module Thermoprint.Identifiers @@ -20,8 +21,11 @@ import Servant.API import Data.Aeson import Data.Set (Set) +import Data.Map (Map) import Data.Sequence (Seq) +import Data.Text (Text) + import GHC.Generics (Generic) import Data.Proxy (Proxy(..)) @@ -33,8 +37,8 @@ data PrinterStatus = Busy JobId | Available deriving (Generic, Show, FromJSON, ToJSON) -data JobStatus = Queued - | Printing +data JobStatus = Queued PrinterId + | Printing PrinterId | Done | Failed PrintingError deriving (Generic, Show, FromJSON, ToJSON) @@ -42,28 +46,27 @@ data JobStatus = Queued data PrintingError = UnknownError deriving (Typeable, Generic, Show, FromJSON, ToJSON, Exception) -type ThermoprintAPI = "printers" :> Get '[JSON] (Set PrinterId) - :<|> "printer" :> Capture "printerId" PrinterId :> ( - ReqBody '[JSON] Printout :> Post '[JSON] JobId - :<|> "status" :> Get '[JSON] PrinterStatus - ) +type DraftTitle = Text + +type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) :<|> "jobs" :> ( - QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq JobId) + QueryParam "printer" PrinterId :> QueryParam "min" JobId :> QueryParam "max" JobId :> Get '[JSON] (Seq (JobId, JobStatus)) + :<|> QueryParam "printer" PrinterId :> ReqBody '[JSON] Printout :> Post '[JSON] JobId ) :<|> "job" :> Capture "jobId" JobId :> ( Get '[JSON] Printout :<|> "status" :> Get '[JSON] JobStatus - :<|> "printer" :> Get '[JSON] PrinterId :<|> Delete '[] () ) :<|> "drafts" :> ( - Get '[JSON] (Set DraftId) - :<|> ReqBody '[JSON] Printout :> Post '[JSON] DraftId + Get '[JSON] (Map DraftId (Maybe DraftTitle)) + :<|> QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Post '[JSON] DraftId ) :<|> "draft" :> Capture "draftId" DraftId :> ( - ReqBody '[JSON] Printout :> Put '[] () - :<|> Get '[JSON] Printout + QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Put '[] () + :<|> Get '[JSON] (Maybe DraftTitle, Printout) :<|> Delete '[] () + :<|> QueryParam "printer" PrinterId :> Post '[JSON] JobId ) thermoprintAPI :: Proxy ThermoprintAPI -- cgit v1.2.3