added JSON view to comments

This commit is contained in:
Yann Esposito (Yogsototh) 2018-12-14 00:07:47 +01:00
parent 08985373c5
commit 00d56b1073
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
2 changed files with 10 additions and 1 deletions

View file

@ -34,7 +34,7 @@ import Servant
import Servant.HTML.Blaze
type CommentAPI =
"comments" :> Capture "slug" Text :> Get '[HTML] CommentPage
"comments" :> Capture "slug" Text :> Get '[HTML,JSON] CommentPage
:<|> "slugs" :> Get '[JSON] [Slug]
:<|> "comments" :> ReqBody '[JSON, FormUrlEncoded] NewComment :> Post '[JSON] Comment

View file

@ -88,6 +88,12 @@ instance ( Serialize a
put i = put (IxSet.toList i)
get = fmap IxSet.fromList get
instance ( Ord a
, ToJSON a
, IxSet.Indexable a
, Typeable a) => ToJSON (IxSet.IxSet a) where
toJSON i = toJSON (IxSet.toList i)
-- * Comment
data DecodeUUIDException = DecodeUUIDException deriving (Show)
@ -280,6 +286,9 @@ data CommentPage =
, comments :: Comments
}
instance ToJSON CommentPage where
toJSON cp = toJSON (comments cp)
instance H.ToMarkup CommentPage where
toMarkup CommentPage {..} = do
let roots = comments IxSet.@= ParentId Nothing