mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-01-10 17:06:47 +09:00
17 lines
661 B
Haskell
17 lines
661 B
Haskell
|
module Handler.Comment where
|
||
|
|
||
|
import Import
|
||
|
|
||
|
postCommentR :: Handler Value
|
||
|
postCommentR = do
|
||
|
-- requireJsonBody will parse the request body into the appropriate type, or return a 400 status code if the request JSON is invalid.
|
||
|
-- (The ToJSON and FromJSON instances are derived in the config/models file).
|
||
|
comment <- (requireJsonBody :: Handler Comment)
|
||
|
|
||
|
-- The YesodAuth instance in Foundation.hs defines the UserId to be the type used for authentication.
|
||
|
maybeCurrentUserId <- maybeAuthId
|
||
|
let comment' = comment { commentUserId = maybeCurrentUserId }
|
||
|
|
||
|
insertedComment <- runDB $ insertEntity comment'
|
||
|
returnJson insertedComment
|