From 0a230e76449680943830f2cf6faf530e22e599e9 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 3 Oct 2017 13:31:53 +1100 Subject: [PATCH] Remove unused Comment functionality from the scaffolding --- config/routes | 2 -- src/Application.hs | 1 - src/Foundation.hs | 1 - src/Handler/Comment.hs | 16 -------------- test/Handler/CommentSpec.hs | 43 ------------------------------------- 5 files changed, 63 deletions(-) delete mode 100644 src/Handler/Comment.hs delete mode 100644 test/Handler/CommentSpec.hs diff --git a/config/routes b/config/routes index 7a48683..2056d8d 100644 --- a/config/routes +++ b/config/routes @@ -6,6 +6,4 @@ / HomeR GET -/comments CommentR POST - /profile ProfileR GET diff --git a/src/Application.hs b/src/Application.hs index 799f4ec..ad91def 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -49,7 +49,6 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, -- Don't forget to add new modules to your cabal file! import Handler.Common import Handler.Home -import Handler.Comment import Handler.Profile -- This line actually creates our YesodDispatch instance. It is the second half diff --git a/src/Foundation.hs b/src/Foundation.hs index 925a486..af45a8c 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -150,7 +150,6 @@ instance Yesod App where -- Routes not requiring authentication. isAuthorized (AuthR _) _ = return Authorized - isAuthorized CommentR _ = return Authorized isAuthorized HomeR _ = return Authorized isAuthorized FaviconR _ = return Authorized isAuthorized RobotsR _ = return Authorized diff --git a/src/Handler/Comment.hs b/src/Handler/Comment.hs deleted file mode 100644 index edb20a8..0000000 --- a/src/Handler/Comment.hs +++ /dev/null @@ -1,16 +0,0 @@ -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 diff --git a/test/Handler/CommentSpec.hs b/test/Handler/CommentSpec.hs deleted file mode 100644 index 0b5225c..0000000 --- a/test/Handler/CommentSpec.hs +++ /dev/null @@ -1,43 +0,0 @@ -{-# LANGUAGE NoImplicitPrelude #-} -{-# LANGUAGE OverloadedStrings #-} -module Handler.CommentSpec (spec) where - -import TestImport -import Data.Aeson - -spec :: Spec -spec = withApp $ do - describe "valid request" $ do - it "gives a 200" $ do - get HomeR - statusIs 200 - - let message = "My message" :: Text - body = object [ "message" .= message ] - encoded = encode body - - request $ do - setMethod "POST" - setUrl CommentR - setRequestBody encoded - addRequestHeader ("Content-Type", "application/json") - - statusIs 200 - - [Entity _id comment] <- runDB $ selectList [CommentMessage ==. message] [] - assertEq "Should have " comment (Comment message Nothing) - - describe "invalid requests" $ do - it "400s when the JSON body is invalid" $ do - get HomeR - - let body = object [ "foo" .= ("My message" :: Value) ] - - request $ do - setMethod "POST" - setUrl CommentR - setRequestBody $ encode body - addRequestHeader ("Content-Type", "application/json") - - statusIs 400 -