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
|
{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving, NoDeriveAnyClass #-}
-- | Typesafe identifiers for our various objects
module Thermoprint.Identifiers
( PrinterId(..)
, JobId(..)
, DraftId(..)
, castId
) where
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import Control.DeepSeq (NFData)
import Servant.API (ToText, FromText)
import Data.Aeson (FromJSON, ToJSON)
newtype PrinterId = PrinterId Integer
deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromText, ToText, FromJSON, ToJSON, Typeable, Generic, NFData)
newtype JobId = JobId Integer
deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromText, ToText, FromJSON, ToJSON, Typeable, Generic, NFData)
newtype DraftId = DraftId Integer
deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromText, ToText, FromJSON, ToJSON, Typeable, Generic, NFData)
castId :: (Integral a, Enum b) => a -> b
castId = toEnum . fromInteger . toInteger
|