Comment.hs 661 B

1234567891011121314151617
  1. module Handler.Comment where
  2. import Import
  3. postCommentR :: Handler Value
  4. postCommentR = do
  5. -- requireJsonBody will parse the request body into the appropriate type, or return a 400 status code if the request JSON is invalid.
  6. -- (The ToJSON and FromJSON instances are derived in the config/models file).
  7. comment <- (requireJsonBody :: Handler Comment)
  8. -- The YesodAuth instance in Foundation.hs defines the UserId to be the type used for authentication.
  9. maybeCurrentUserId <- maybeAuthId
  10. let comment' = comment { commentUserId = maybeCurrentUserId }
  11. insertedComment <- runDB $ insertEntity comment'
  12. returnJson insertedComment