added JSON view to comments
This commit is contained in:
parent
08985373c5
commit
00d56b1073
2 changed files with 10 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue