Update with empty json (#852)
This commit is contained in:
committed by
Joe Nelson
parent
56bdf59e14
commit
8557ee55f5
+1
-1
@@ -8,9 +8,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
### Added
|
### Added
|
||||||
- Allow requesting binary output on GET - @steve-chavez
|
- Allow requesting binary output on GET - @steve-chavez
|
||||||
- Accept clients requesting `Content-Type: application/json` from / - @feynmanliang
|
- Accept clients requesting `Content-Type: application/json` from / - @feynmanliang
|
||||||
|
- #493, Updating with empty JSON object makes zero updates @koulakis
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- #827, Avoid Warp reaper, extend socket timeout to 1 hour - @majorcode
|
- #827, Avoid Warp reaper, extend socket timeout to 1 hour - @majorcode
|
||||||
- #791, malformed nested JSON error - @diogob
|
- #791, malformed nested JSON error - @diogob
|
||||||
- Resource embedding in views referencing tables in public schema - @fab1an
|
- Resource embedding in views referencing tables in public schema - @fab1an
|
||||||
|
|||||||
@@ -165,10 +165,12 @@ app dbStructure conf apiRequest =
|
|||||||
if iPreferRepresentation apiRequest == Full
|
if iPreferRepresentation apiRequest == Full
|
||||||
then toS body else ""
|
then toS body else ""
|
||||||
|
|
||||||
(ActionUpdate, TargetIdent _, Just payload) ->
|
(ActionUpdate, TargetIdent _, Just payload@(PayloadJSON rows)) ->
|
||||||
case mutateSqlParts of
|
case (mutateSqlParts, null <$> rows V.!? 0, iPreferRepresentation apiRequest == Full) of
|
||||||
Left errorResponse -> return errorResponse
|
(Left errorResponse, _, _) -> return errorResponse
|
||||||
Right (sq, mq) -> do
|
(_, Just True, True) -> return $ responseLBS status200 [contentRangeH 1 0 Nothing] "[]"
|
||||||
|
(_, Just True, False) -> return $ responseLBS status204 [contentRangeH 1 0 Nothing] ""
|
||||||
|
(Right (sq, mq), _, _) -> do
|
||||||
let stm = createWriteStatement sq mq
|
let stm = createWriteStatement sq mq
|
||||||
(contentType == CTSingularJSON) False (contentType == CTTextCSV)
|
(contentType == CTSingularJSON) False (contentType == CTTextCSV)
|
||||||
(iPreferRepresentation apiRequest) []
|
(iPreferRepresentation apiRequest) []
|
||||||
|
|||||||
@@ -413,6 +413,30 @@ spec = do
|
|||||||
[json| { id: 99 } |]
|
[json| { id: 99 } |]
|
||||||
`shouldRespondWith` [json| [{id:99}] |]
|
`shouldRespondWith` [json| [{id:99}] |]
|
||||||
{ matchHeaders = [matchContentTypeJson] }
|
{ matchHeaders = [matchContentTypeJson] }
|
||||||
|
-- put value back for other tests
|
||||||
|
void $ request methodPatch "/items?id=eq.99" [] [json| { "id":1 } |]
|
||||||
|
|
||||||
|
it "makes no updates and returns 204, when patching with an empty json object" $ do
|
||||||
|
request methodPatch "/items" [] [json| {} |]
|
||||||
|
`shouldRespondWith` ""
|
||||||
|
{
|
||||||
|
matchStatus = 204,
|
||||||
|
matchHeaders = ["Content-Range" <:> "*/*"]
|
||||||
|
}
|
||||||
|
|
||||||
|
g <- get "/items"
|
||||||
|
liftIO $ simpleBody g `shouldBe` [json| [{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15},{id:16},{"id":2},{"id":1}] |]
|
||||||
|
|
||||||
|
it "makes no updates and and returns 200, when patching with an empty json object and return=rep" $ do
|
||||||
|
request methodPatch "/items" [("Prefer", "return=representation")] [json| {} |]
|
||||||
|
`shouldRespondWith` "[]"
|
||||||
|
{
|
||||||
|
matchStatus = 200,
|
||||||
|
matchHeaders = ["Content-Range" <:> "*/*"]
|
||||||
|
}
|
||||||
|
|
||||||
|
g <- get "/items"
|
||||||
|
liftIO $ simpleBody g `shouldBe` [json| [{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15},{id:16},{"id":2},{"id":1}] |]
|
||||||
|
|
||||||
context "with unicode values" $
|
context "with unicode values" $
|
||||||
it "succeeds and returns values intact" $ do
|
it "succeeds and returns values intact" $ do
|
||||||
|
|||||||
Reference in New Issue
Block a user