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 | ActionUpdate | ActionDelete
| ActionInfo | ActionInvoke | ActionInfo | ActionInvoke
| ActionInspect | ActionInspect
| ActionInappropriate
deriving Eq deriving Eq
-- | The target db object of a user action -- | The target db object of a user action
data Target = TargetIdent QualifiedIdentifier data Target = TargetIdent QualifiedIdentifier
@@ -181,7 +180,7 @@ userApiRequest schema req reqBody
"PATCH" -> ActionUpdate "PATCH" -> ActionUpdate
"DELETE" -> ActionDelete "DELETE" -> ActionDelete
"OPTIONS" -> ActionInfo "OPTIONS" -> ActionInfo
_ -> ActionInappropriate _ -> ActionInspect
target = case path of target = case path of
[] -> TargetRoot [] -> TargetRoot
[table] -> TargetIdent [table] -> TargetIdent
+3 -7
View File
@@ -95,8 +95,8 @@ postgrest conf refDbStructure pool getTime =
(HT.run handleReq HT.ReadCommitted txMode) (HT.run handleReq HT.ReadCommitted txMode)
respond resp respond resp
where where
respondToError error = respondToError err =
case error of case err of
ErrorActionInappropriate -> errResponse status405 "Bad Request" ErrorActionInappropriate -> errResponse status405 "Bad Request"
ErrorInvalidBody errorMessage -> errResponse status400 $ toS errorMessage ErrorInvalidBody errorMessage -> errResponse status400 $ toS errorMessage
@@ -286,10 +286,7 @@ app dbStructure conf apiRequest =
else response else response
responseContentTypeOrError :: [ContentType] -> Action -> Either Response ContentType responseContentTypeOrError :: [ContentType] -> Action -> Either Response ContentType
responseContentTypeOrError accepts action = responseContentTypeOrError accepts action = serves contentTypesForRequest accepts
case action of
ActionInappropriate -> Left $ errResponse status405 "Unsupported HTTP verb"
_ -> serves contentTypesForRequest accepts
where where
contentTypesForRequest = contentTypesForRequest =
case action of case action of
@@ -300,7 +297,6 @@ responseContentTypeOrError accepts action =
ActionInvoke -> [CTApplicationJSON] ActionInvoke -> [CTApplicationJSON]
ActionInspect -> [CTOpenAPI] ActionInspect -> [CTOpenAPI]
ActionInfo -> [CTTextCSV] ActionInfo -> [CTTextCSV]
ActionInappropriate -> []
serves sProduces cAccepts = serves sProduces cAccepts =
case mutuallyAgreeable sProduces cAccepts of case mutuallyAgreeable sProduces cAccepts of
Nothing -> do Nothing -> do