Skip to content

Commit

Permalink
posts: delete post via json
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed Aug 17, 2019
1 parent 4922c8d commit 166aa28
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/routes
Expand Up @@ -17,3 +17,4 @@
/posts/#PostId PostR DELETE /posts/#PostId PostR DELETE


/api/posts ApiPostsR GET POST /api/posts ApiPostsR GET POST
/api/posts/#PostId ApiPostR DELETE
1 change: 1 addition & 0 deletions src/Foundation.hs
Expand Up @@ -182,6 +182,7 @@ instance Yesod App where
isAuthorized PostsR _ = isAuthenticated isAuthorized PostsR _ = isAuthenticated
isAuthorized ApiPostsR _ = isAuthenticated isAuthorized ApiPostsR _ = isAuthenticated
isAuthorized (PostR postId) _ = isOwner postId isAuthorized (PostR postId) _ = isOwner postId
isAuthorized (ApiPostR postId) _ = isOwner postId


-- This function creates static content files in the static folder -- This function creates static content files in the static folder
-- and names them based on a hash of their content. This allows -- 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 @@ -123,3 +123,8 @@ deletePostR :: PostId -> Handler Html
deletePostR postId = do deletePostR postId = do
_ <- runDB $ delete postId _ <- runDB $ delete postId
redirect PostsR redirect PostsR

deleteApiPostR :: PostId -> Handler Value
deleteApiPostR postId = do
_ <- runDB $ delete postId
return Null

0 comments on commit 166aa28

Please sign in to comment.