1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-23 03:44:45 +03:00

Add guidance about handling requests without persistent storage.

There is no persistent storage in the application by the time we're expecting
students to write ``Response`` handling functions. So add some more guidance
that we only expect placeholder values to be used, this wasn't sufficiently
clear. Fixes #3

Updated the latter placeholder values to match the guidance offered, for
consistency.

Updated the configuration ``helloMsg`` value and some of the tests to be a bit
more sensible, even if only a little.
This commit is contained in:
Sean Chalmers 2017-09-11 10:27:35 +10:00
parent 71a5c2f275
commit ec1bb07dae
10 changed files with 20 additions and 16 deletions

View File

@ -117,10 +117,14 @@ mkRequest =
--
-- Reduction of concerns such that each section of the application only deals
-- with a small piece is one of the benefits of developing in this way.
--
-- For now, return a made-up value for each of the responses as we don't have
-- any persistent storage. Plain text responses that contain "X not implemented
-- yet" should be sufficient.
handleRequest
:: RqType
-> Either Error Response
handleRequest _ =
handleRequest =
error "handleRequest not implemented"
-- Reimplement this function using the new functions and the ``RqType``

View File

@ -83,9 +83,9 @@ handleRequest
handleRequest _cfg (AddRq _ _) =
Right $ resp200 PlainText ("App says: " <> undefined)
handleRequest _ (ViewRq _) =
Right $ resp200 PlainText "Susan was here"
Right $ resp200 PlainText "View Request not implemented"
handleRequest _ ListRq =
Right $ resp200 PlainText "[ \"Fred was here\", \"Susan was here\" ]"
Right $ resp200 PlainText "List Request not implemented"
mkRequest
:: Request

View File

@ -1,4 +1,4 @@
{
"port": 33,
"helloMsg": "Oh, hurro!"
"helloMsg": "Functional Programming is neat."
}

View File

@ -76,9 +76,9 @@ handleRequest
handleRequest cfg (AddRq _ _) =
Right $ resp200 PlainText (Conf.mkMessage cfg)
handleRequest _ (ViewRq _) =
Right $ resp200 PlainText "Susan was here"
Right $ resp200 PlainText "View Request not implemented"
handleRequest _ ListRq =
Right $ resp200 PlainText "[ \"Fred was here\", \"Susan was here\" ]"
Right $ resp200 PlainText "List Request not implemented"
mkRequest
:: Request

View File

@ -1,6 +1,6 @@
{
"port": 3000,
"helloMsg": "Oh, hurro!",
"helloMsg": "Functional Programming is neat.",
"tableName": "comments",
"dbName": "firstapp"
}

View File

@ -50,11 +50,11 @@ main = do
-- ViewRq Spec
describe "GET /topic/view" $ do
it "Should return 200 with content" $ do
post "/fudge/add" "Fred"
post "/fudge/add" "Is super tasty."
get "/fudge/view" `shouldRespondWith` 200
-- ListRq Spec
describe "GET /list" $ do
it "Should return 200 with content" $ do
post "/fudge/add" "Fred"
post "/fudge/add" "Is super tasty."
get "/list" `shouldRespondWith` "[\"fudge\"]"

View File

@ -1,6 +1,6 @@
{
"port": 3000,
"helloMsg": "Oh, hurro!",
"helloMsg": "Functional Programming is neat.",
"tableName": "comments",
"dbName": "firstapp"
}

View File

@ -46,11 +46,11 @@ main = do
-- ViewRq Spec
describe "GET /topic/view" $ do
it "Should return 200 with content" $ do
post "/fudge/add" "Fred"
post "/fudge/add" "Is super tasty."
get "/fudge/view" `shouldRespondWith` 200
-- ListRq Spec
describe "GET /list" $ do
it "Should return 200 with content" $ do
post "/fudge/add" "Fred"
post "/fudge/add" "Is super tasty."
get "/list" `shouldRespondWith` "[\"fudge\"]"

View File

@ -1,6 +1,6 @@
{
"port": 3000,
"helloMsg": "Oh, hurro!",
"helloMsg": "Functional Programming is neat.",
"tableName": "comments",
"dbName": "firstapp"
}

View File

@ -55,7 +55,7 @@ main = do
-- AddRq Spec
describe "POST /topic/add" $ do
it "Should return 200 with well formed request" $ do
pOST "Fred" `shouldRespondWith` "Success"
pOST "Is super tasty." `shouldRespondWith` "Success"
it "Should 400 on empty input" $
pOST "" `shouldRespondWith` 400
@ -63,11 +63,11 @@ main = do
-- ViewRq Spec
describe "GET /topic/view" $ do
it "Should return 200 with content" $ do
_ <- pOST "Fred"
_ <- pOST "Is super tasty."
get ( "/" <> testTopic <> "/view" ) `shouldRespondWith` 200
-- ListRq Spec
describe "GET /list" $ do
it "Should return 200 with content" $ do
_ <- pOST "Fred"
_ <- pOST "Is super tasty."
get "/list" `shouldRespondWith` "[\"fudge\"]"