Make response logic more dry and lazy

This commit is contained in:
Joe Nelson
2014-07-13 10:18:58 -07:00
parent d7a3685002
commit 919d827b24
+4 -3
View File
@@ -47,9 +47,10 @@ app :: AppConfig -> Application
app config req respond = app config req respond =
case path of case path of
[] -> respond =<< responseLBS status200 [json] <$> (printTables =<< conn) [] -> respond =<< responseLBS status200 [json] <$> (printTables =<< conn)
[table] -> respond =<< if verb == methodOptions [table] -> respond =<< (<$>) (responseLBS status200 [json])
then responseLBS status200 [json] <$> (printColumns table =<< conn) ( if verb == methodOptions
else responseLBS status200 [json] <$> (selectWhere table qq =<< conn) then printColumns table =<< conn
else selectWhere table qq =<< conn )
_ -> respond $ responseLBS status404 [] "" _ -> respond $ responseLBS status404 [] ""
where where
path = pathInfo req path = pathInfo req