dmfix/src/Handler/Comment.hs
2021-09-21 16:22:34 -04:00

20 lines
584 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Handler.Comment where
import Import
import Data.Aeson
newtype Comment = Comment Text
instance ToJSON Comment where
toJSON (Comment t) = object ["message" .= t]
instance FromJSON Comment where
parseJSON = withObject "Comment" $ \o -> Comment <$> o .: "message"
postCommentR :: Handler Value
postCommentR = do
-- requireCheckJsonBody will parse the request body into the appropriate type, or return a 400 status code if the request JSON is invalid.
comment <- requireCheckJsonBody :: Handler Comment
returnJson comment