module Data.UserId where
import Control.Applicative ((<$>))
import Control.Lens ((?=), (.=), (^.), (.~), makeLenses, view, set)
import Data.Aeson (FromJSON(..), ToJSON(..), Result(..), fromJSON)
import Data.Data (Data)
import Data.SafeCopy (SafeCopy, base, deriveSafeCopy)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import Text.Boomerang.TH (makeBoomerangs)
import Web.Routes (PathInfo(..))
import Web.Routes.TH (derivePathInfo)
newtype UserId = UserId { _unUserId :: Integer }
deriving (Eq, Ord, Enum, Read, Show, Data, Typeable, Generic)
deriveSafeCopy 1 'base ''UserId
makeLenses ''UserId
makeBoomerangs ''UserId
instance ToJSON UserId where toJSON (UserId i) = toJSON i
instance FromJSON UserId where parseJSON v = UserId <$> parseJSON v
instance PathInfo UserId where
toPathSegments (UserId i) = toPathSegments i
fromPathSegments = UserId <$> fromPathSegments
succUserId :: UserId -> UserId
succUserId (UserId i) = UserId (succ i)