From 898752c25684cf7a4d7a2546c6f9dbca489f5a4c Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Thu, 10 Oct 2019 10:06:30 -0400
Subject: [PATCH] Bug 14697: Move /return_claims/claim to /return_claims

---
 Koha/REST/V1/ReturnClaims.pm                 |  3 +--
 api/v1/swagger/paths.json                    |  4 ++--
 api/v1/swagger/paths/return_claims.json      | 13 +++++--------
 koha-tmpl/intranet-tmpl/prog/js/checkouts.js |  3 ++-
 t/db_dependent/api/v1/return_claims.t        |  9 ++++++---
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/Koha/REST/V1/ReturnClaims.pm b/Koha/REST/V1/ReturnClaims.pm
index b1c080f311..ec5edc82bc 100644
--- a/Koha/REST/V1/ReturnClaims.pm
+++ b/Koha/REST/V1/ReturnClaims.pm
@@ -37,10 +37,9 @@ Claim that a checked out item was returned.
 
 sub claim_returned {
     my $c     = shift->openapi->valid_input or return;
-    my $input = $c->validation->output;
     my $body  = $c->validation->param('body');
 
-    my $itemnumber      = $input->{item_id};
+    my $itemnumber      = $body->{item_id};
     my $charge_lost_fee = $body->{charge_lost_fee} ? 1 : 0;
     my $created_by      = $body->{created_by};
     my $notes           = $body->{notes};
diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json
index aa0102013f..8b9041460d 100644
--- a/api/v1/swagger/paths.json
+++ b/api/v1/swagger/paths.json
@@ -86,8 +86,8 @@
   "/public/patrons/{patron_id}/guarantors/can_see_checkouts": {
     "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
   },
-  "/return_claims/claim/{item_id}/": {
-    "$ref": "paths/return_claims.json#/~1return_claims~1claim~1{item_id}"
+  "/return_claims": {
+    "$ref": "paths/return_claims.json#/~1return_claims"
   },
   "/return_claims/{claim_id}/notes": {
     "$ref": "paths/return_claims.json#/~1return_claims~1{claim_id}~1notes"
diff --git a/api/v1/swagger/paths/return_claims.json b/api/v1/swagger/paths/return_claims.json
index 0289857672..b467739cb8 100644
--- a/api/v1/swagger/paths/return_claims.json
+++ b/api/v1/swagger/paths/return_claims.json
@@ -1,5 +1,5 @@
 {
-  "/return_claims/claim/{item_id}": {
+  "/return_claims": {
     "post": {
       "x-mojo-to": "ReturnClaims#claim_returned",
       "operationId": "claimReturned",
@@ -10,13 +10,6 @@
         "claim"
       ],
       "parameters": [
-        {
-          "name": "item_id",
-          "in": "path",
-          "required": true,
-          "description": "Itemnumber of item to claim as returned",
-          "type": "integer"
-        },
         {
           "name": "body",
           "in": "body",
@@ -25,6 +18,10 @@
           "schema": {
             "type": "object",
             "properties": {
+              "item_id" : {
+                "description": "Internal item id to claim as returned",
+                "type": "integer"
+              },
               "notes": {
                 "description": "Notes about this return claim",
                 "type": "string"
diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
index 06fd7f432c..f18a5d2070 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
@@ -845,12 +845,13 @@ $(document).ready(function() {
         $(`.claim-returned-btn[data-itemnumber='${itemnumber}']`).replaceWith(`<img id='return_claim_spinner_${itemnumber}' src='${interface}/${theme}/img/spinner-small.gif' />`);
 
         params = {
+            item_id: itemnumber,
             notes: notes,
             charge_lost_fee: fee,
             created_by: $.cookie("lastborrowernumber")
         };
 
-        $.post( `/api/v1/return_claims/claim/${itemnumber}`, JSON.stringify(params), function( data ) {
+        $.post( '/api/v1/return_claims', JSON.stringify(params), function( data ) {
 
             id = "#return_claim_spinner_" + data.itemnumber;
 
diff --git a/t/db_dependent/api/v1/return_claims.t b/t/db_dependent/api/v1/return_claims.t
index f377ccd277..215c0ee7fe 100644
--- a/t/db_dependent/api/v1/return_claims.t
+++ b/t/db_dependent/api/v1/return_claims.t
@@ -81,7 +81,8 @@ t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', '99' );
 # Test creating a return claim
 ## Invalid id
 $t->post_ok(
-    "//$userid:$password@/api/v1/return_claims/claim/1" => json => {
+    "//$userid:$password@/api/v1/return_claims" => json => {
+        item_id         => 1,
         charge_lost_fee => Mojo::JSON->false,
         created_by      => $librarian->id,
         notes           => "This is a test note."
@@ -90,7 +91,8 @@ $t->post_ok(
 
 ## Valid id
 $t->post_ok(
-    "//$userid:$password@/api/v1/return_claims/claim/$itemnumber1" => json => {
+    "//$userid:$password@/api/v1/return_claims" => json => {
+        item_id         => $itemnumber1,
         charge_lost_fee => Mojo::JSON->false,
         created_by      => $librarian->id,
         notes           => "This is a test note."
@@ -100,7 +102,8 @@ my $claim_id = $t->tx->res->json->{id};
 
 ## Duplicate id
 $t->post_ok(
-    "//$userid:$password@/api/v1/return_claims/claim/$itemnumber1" => json => {
+    "//$userid:$password@/api/v1/return_claims" => json => {
+        item_id         => $itemnumber1,
         charge_lost_fee => Mojo::JSON->false,
         created_by      => $librarian->id,
         notes           => "This is a test note."
-- 
2.21.0 (Apple Git-122)