Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
posts: delete button
  • Loading branch information
3v0k4 committed Jul 20, 2019
1 parent 716817e commit 4fea7c6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/routes
Expand Up @@ -14,3 +14,4 @@
/profile ProfileR GET
/ LandingR GET POST
/posts PostsR GET POST
/posts/#PostId PostR DELETE
1 change: 1 addition & 0 deletions src/Foundation.hs
Expand Up @@ -174,6 +174,7 @@ instance Yesod App where
isAuthorized LandingR _ = return Authorized

isAuthorized PostsR _ = return Authorized
isAuthorized (PostR _) _ = return Authorized

-- This function creates static content files in the static folder
-- and names them based on a hash of their content. This allows
Expand Down
5 changes: 5 additions & 0 deletions src/Handler/Posts.hs
Expand Up @@ -33,3 +33,8 @@ postPostsR = do
_ ->
emptyLayout $ do
$(widgetFile "posts")

deletePostR :: PostId -> Handler Html
deletePostR postId = do
_ <- runDB $ delete postId
redirect PostsR
2 changes: 2 additions & 0 deletions templates/posts.hamlet
Expand Up @@ -13,3 +13,5 @@
<li>
<h2> #{postTitle $ entityVal post}
<p> #{postText $ entityVal post}
<form method=post action=@{PostR $ entityKey post}?_method=DELETE>
<button>Delete

0 comments on commit 4fea7c6

Please sign in to comment.