{-# LANGUAGE DataKinds, TypeOperators, DeriveGeneric #-} module Thermoprint.Api ( ThermoprintApi ) where import Thermoprint import Data.Aeson import Servant.API import qualified Data.Text.Lazy as Text import qualified Data.ByteString.Lazy.Char8 as ByteString import Data.ByteString.Lazy.Char8 (ByteString) import GHC.Generics import Control.Monad import Data.Int (Int64) instance ToJSON ByteString where toJSON = toJSON . Text.pack . ByteString.unpack instance FromJSON ByteString where parseJSON value = (ByteString.pack . Text.unpack) `liftM` parseJSON value instance ToJSON c => ToJSON (Inline c) instance FromJSON c => FromJSON (Inline c) instance ToJSON c => ToJSON (Block c) instance FromJSON c => FromJSON (Block c) type ThermoprintApi = "print" :> Capture "printerId" Integer :> ReqBody '[JSON] (Block String) :> Post '[JSON] () :<|> "drafts" :> Get '[JSON] [(Int64, String)] :<|> "drafts" :> ReqBody '[JSON] (String, Block String) :> Put '[JSON] Int64 :<|> "drafts" :> Capture "draftId" Int64 :> Get '[JSON] (String, Block String) :<|> "drafts" :> Capture "draftId" Int64 :> ReqBody '[JSON] (String, Block String) :> Put '[JSON] () :<|> "drafts" :> Capture "draftId" Int64 :> Delete '[JSON] ()