Bug 25048: Make successful resource deletion return 204
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 2 Apr 2020 21:40:49 +0000 (18:40 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 29 Apr 2020 15:24:43 +0000 (16:24 +0100)
This patch adapts the spec and the controllers so existing routes return
204 and an empty response body when a successful deletion happens.

Right now we have a coding guideline but haven't adapted the existing
routes.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Some tests fail
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/REST/V1/Acquisitions/Vendors.pm
Koha/REST/V1/Cities.pm
Koha/REST/V1/Holds.pm
Koha/REST/V1/Patrons.pm
api/v1/swagger/paths/acquisitions_orders.json
api/v1/swagger/paths/acquisitions_vendors.json
api/v1/swagger/paths/cities.json
api/v1/swagger/paths/holds.json
api/v1/swagger/paths/patrons.json

index 8fcf715..8720a42 100644 (file)
@@ -159,7 +159,7 @@ sub delete {
         $vendor->delete;
 
         return $c->render(
-            status  => 200,
+            status  => 204,
             openapi => q{}
         );
     }
index 6b76daa..cfa8d53 100644 (file)
@@ -126,7 +126,10 @@ sub delete {
 
     return try {
         $city->delete;
-        return $c->render( status => 200, openapi => "" );
+        return $c->render(
+            status  => 204,
+            openapi => q{}
+        );
     }
     catch {
         $c->unhandled_exception($_);
index 2a8c055..87d7c05 100644 (file)
@@ -262,7 +262,10 @@ sub delete {
     return try {
         $hold->cancel;
 
-        return $c->render( status => 200, openapi => {} );
+        return $c->render(
+            status  => 204,
+            openapi => q{}
+        );
     }
     catch {
         $c->unhandled_exception($_);
index 8ff645c..331ced1 100644 (file)
@@ -279,7 +279,10 @@ sub delete {
 
         # check if loans, reservations, debarrment, etc. before deletion!
         $patron->delete;
-        return $c->render( status => 200, openapi => {} );
+        return $c->render(
+            status  => 204,
+            openapi => q{}
+        );
     }
     catch {
         unless ($patron) {
index a0232d8..b9e0020 100644 (file)
             ],
             "responses": {
                 "204": {
-                    "description": "Order deleted",
-                    "schema": {
-                        "type": "string"
-                    }
+                    "description": "Order deleted"
                 },
                 "401": {
                     "description": "Authentication required",
index 0295231..2e1eb88 100644 (file)
         "application/json"
       ],
       "responses": {
-        "200": {
-          "description": "Vendor deleted",
-          "schema": {
-            "type": "string"
-          }
+        "204": {
+          "description": "Vendor deleted"
         },
         "401": {
           "description": "Authentication required",
index 77ee394..01c7bed 100644 (file)
         "application/json"
       ],
       "responses": {
-        "200": {
-          "description": "City deleted",
-          "schema": {
-            "type": "string"
-          }
+        "204": {
+          "description": "City deleted"
         },
         "401": {
           "description": "Authentication required",
index 2bb0ed0..e4e925d 100644 (file)
       ],
       "produces": ["application/json"],
       "responses": {
-        "200": {
-          "description": "Successful deletion",
-          "schema": {
-            "type": "object"
-          }
+        "204": {
+          "description": "Hold deleted"
         },
         "401": {
           "description": "Authentication required",
index c8798f2..3e4e773 100644 (file)
       }],
       "produces": ["application/json"],
       "responses": {
-        "200": {
-          "description": "Patron deleted successfully",
-          "schema": {
-            "type": "object"
-          }
+        "204": {
+          "description": "Patron deleted"
         },
         "400": {
           "description": "Patron deletion failed",