diff options
| -rw-r--r-- | spec/src/Thermoprint/API.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 4b10130..6c86008 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs | |||
| @@ -22,8 +22,12 @@ 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 Data.Sequence (Seq) | 26 | import Data.Sequence (Seq) |
| 26 | 27 | ||
| 28 | import Data.IntMap.Strict (IntMap) | ||
| 29 | import qualified Data.IntMap.Strict as IntMap (foldMapWithKey, singleton) | ||
| 30 | |||
| 27 | import Data.Text (Text) | 31 | import Data.Text (Text) |
| 28 | 32 | ||
| 29 | import GHC.Generics (Generic) | 33 | import GHC.Generics (Generic) |
| @@ -33,6 +37,13 @@ import Data.Proxy (Proxy(..)) | |||
| 33 | import Control.Exception (Exception) | 37 | import Control.Exception (Exception) |
| 34 | import Data.Typeable (Typeable) | 38 | import Data.Typeable (Typeable) |
| 35 | 39 | ||
| 40 | instance (Integral k, Ord k, ToJSON v) => ToJSON (Map k v) where | ||
| 41 | toJSON = toJSON . Map.foldMapWithKey (IntMap.singleton . castId) | ||
| 42 | |||
| 43 | instance (Enum k, Ord k, FromJSON v) => FromJSON (Map k v) where | ||
| 44 | parseJSON = fmap (IntMap.foldMapWithKey $ Map.singleton . castId) . parseJSON | ||
| 45 | |||
| 46 | |||
| 36 | data PrinterStatus = Busy JobId | 47 | data PrinterStatus = Busy JobId |
| 37 | | Available | 48 | | Available |
| 38 | deriving (Generic, Show, FromJSON, ToJSON) | 49 | deriving (Generic, Show, FromJSON, ToJSON) |
