blob: f3318c4d46bee27be0dcf9cdb58d717c18566c47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
{-# 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] ()
|