Remove ActionInappropriate constructor from type Action since now we validate the request before building an ApiRequest.

This commit is contained in:
Diogo Biazus
2016-11-27 23:54:37 -05:00
parent 47c4fbc8ef
commit b8ddc30252
2 changed files with 4 additions and 9 deletions
+1 -2
View File
@@ -48,7 +48,6 @@ data Action = ActionCreate | ActionRead
| ActionUpdate | ActionDelete
| ActionInfo | ActionInvoke
| ActionInspect
| ActionInappropriate
deriving Eq
-- | The target db object of a user action
data Target = TargetIdent QualifiedIdentifier
@@ -181,7 +180,7 @@ userApiRequest schema req reqBody
"PATCH" -> ActionUpdate
"DELETE" -> ActionDelete
"OPTIONS" -> ActionInfo
_ -> ActionInappropriate
_ -> ActionInspect
target = case path of
[] -> TargetRoot
[table] -> TargetIdent
+3 -7
View File
@@ -95,8 +95,8 @@ postgrest conf refDbStructure pool getTime =
(HT.run handleReq HT.ReadCommitted txMode)
respond resp
where
respondToError error =
case error of
respondToError err =
case err of
ErrorActionInappropriate -> errResponse status405 "Bad Request"
ErrorInvalidBody errorMessage -> errResponse status400 $ toS errorMessage
@@ -286,10 +286,7 @@ app dbStructure conf apiRequest =
else response
responseContentTypeOrError :: [ContentType] -> Action -> Either Response ContentType
responseContentTypeOrError accepts action =
case action of
ActionInappropriate -> Left $ errResponse status405 "Unsupported HTTP verb"
_ -> serves contentTypesForRequest accepts
responseContentTypeOrError accepts action = serves contentTypesForRequest accepts
where
contentTypesForRequest =
case action of
@@ -300,7 +297,6 @@ responseContentTypeOrError accepts action =
ActionInvoke -> [CTApplicationJSON]
ActionInspect -> [CTOpenAPI]
ActionInfo -> [CTTextCSV]
ActionInappropriate -> []
serves sProduces cAccepts =
case mutuallyAgreeable sProduces cAccepts of
Nothing -> do