module TD.Data.CommunityId
(CommunityId(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data
=
{ CommunityId -> Maybe Int
_id :: Maybe Int
}
deriving (CommunityId -> CommunityId -> Bool
(CommunityId -> CommunityId -> Bool)
-> (CommunityId -> CommunityId -> Bool) -> Eq CommunityId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommunityId -> CommunityId -> Bool
== :: CommunityId -> CommunityId -> Bool
$c/= :: CommunityId -> CommunityId -> Bool
/= :: CommunityId -> CommunityId -> Bool
Eq, Int -> CommunityId -> ShowS
[CommunityId] -> ShowS
CommunityId -> String
(Int -> CommunityId -> ShowS)
-> (CommunityId -> String)
-> ([CommunityId] -> ShowS)
-> Show CommunityId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommunityId -> ShowS
showsPrec :: Int -> CommunityId -> ShowS
$cshow :: CommunityId -> String
show :: CommunityId -> String
$cshowList :: [CommunityId] -> ShowS
showList :: [CommunityId] -> ShowS
Show)
instance I.ShortShow CommunityId where
shortShow :: CommunityId -> String
shortShow CommunityId
{ _id :: CommunityId -> Maybe Int
_id = Maybe Int
_id_
}
= String
"CommunityId"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
]
instance AT.FromJSON CommunityId where
parseJSON :: Value -> Parser CommunityId
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"communityId" -> Value -> Parser CommunityId
parseCommunityId Value
v
String
_ -> Parser CommunityId
forall a. Monoid a => a
mempty
where
parseCommunityId :: A.Value -> AT.Parser CommunityId
parseCommunityId :: Value -> Parser CommunityId
parseCommunityId = String
-> (Object -> Parser CommunityId) -> Value -> Parser CommunityId
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CommunityId" ((Object -> Parser CommunityId) -> Value -> Parser CommunityId)
-> (Object -> Parser CommunityId) -> Value -> Parser CommunityId
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
CommunityId -> Parser CommunityId
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommunityId -> Parser CommunityId)
-> CommunityId -> Parser CommunityId
forall a b. (a -> b) -> a -> b
$ CommunityId
{ _id :: Maybe Int
_id = Maybe Int
_id_
}
parseJSON Value
_ = Parser CommunityId
forall a. Monoid a => a
mempty