Skip to content
Permalink
Browse files

posts: belong to user

  • Loading branch information...
3v0k4 committed Jul 21, 2019
1 parent dd46b15 commit b9ed6789ed578e4349f9fc0eee670e2df87434be
Showing with 11 additions and 5 deletions.
  1. +1 −0 config/models.persistentmodels
  2. +10 −5 src/Handler/Posts.hs
@@ -19,3 +19,4 @@ Comment json -- Adding "json" causes ToJSON and FromJSON instances to be derived
Post
title Text
text Textarea
userId UserId
@@ -10,21 +10,26 @@ module Handler.Posts where

import Import

postForm :: Form Post
postForm =
postForm :: UserId -> Form Post
postForm userId =
renderDivs $
Post <$> areq textField "Title" Nothing <*> areq textareaField "Text" Nothing
Post <$>
areq textField "Title" Nothing <*>
areq textareaField "Text" Nothing <*>
areq hiddenField "" (Just userId)

getPostsR :: Handler Html
getPostsR = do
(widget, enctype) <- generateFormPost postForm
userId <- fmap fst $ requireAuthPair
(widget, enctype) <- generateFormPost $ postForm userId
allPosts :: [Entity Post] <- runDB $ selectList [] [ Desc PostId ]
emptyLayout $ do
$(widgetFile "posts")

postPostsR :: Handler Html
postPostsR = do
((result, widget), enctype) <- runFormPost postForm
userId <- fmap fst $ requireAuthPair
((result, widget), enctype) <- runFormPost $ postForm userId
allPosts :: [Entity Post] <- runDB $ selectList [] [ Desc PostId ]
case result of
FormSuccess post -> do

0 comments on commit b9ed678

Please sign in to comment.
You can’t perform that action at this time.