From 245774f31be0cfe993eaf8302d25d27874a0231f Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Wed, 20 Oct 2021 18:09:35 -0300
Subject: [PATCH] Bug 29290: Add spec changes

This patch adds the new route. It also tweaks the checkout object
definition to allow embedding the required related objects (for bug 29275).

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 api/v1/swagger/definitions/checkout.json | 21 +++++++
 api/v1/swagger/paths.json                |  3 +
 api/v1/swagger/paths/biblios.json        | 76 ++++++++++++++++++++++++
 api/v1/swagger/paths/checkouts.json      |  8 ++-
 4 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/api/v1/swagger/definitions/checkout.json b/api/v1/swagger/definitions/checkout.json
index 42bdf96e1a..94dd7a2e49 100644
--- a/api/v1/swagger/definitions/checkout.json
+++ b/api/v1/swagger/definitions/checkout.json
@@ -83,6 +83,27 @@
           "null"
       ],
       "description": "The object representing the checkout issuer"
+    },
+    "item": {
+      "type": [
+          "object",
+          "null"
+      ],
+      "description": "The object representing the checked out item"
+    },
+    "library": {
+      "type": [
+          "object",
+          "null"
+      ],
+      "description": "The object representing the checkout library"
+    },
+    "patron": {
+      "type": [
+          "object",
+          "null"
+      ],
+      "description": "The object representing the checkout patron"
     }
   },
   "additionalProperties": false
diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json
index 3d3338e0bd..abb80315f6 100644
--- a/api/v1/swagger/paths.json
+++ b/api/v1/swagger/paths.json
@@ -23,6 +23,9 @@
   "/biblios/{biblio_id}": {
     "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}"
   },
+  "/biblios/{biblio_id}/checkouts": {
+    "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1checkouts"
+  },
   "/biblios/{biblio_id}/items": {
     "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1items"
   },
diff --git a/api/v1/swagger/paths/biblios.json b/api/v1/swagger/paths/biblios.json
index f1b494ddb1..f16e9fe3da 100644
--- a/api/v1/swagger/paths/biblios.json
+++ b/api/v1/swagger/paths/biblios.json
@@ -132,6 +132,82 @@
       }
     }
   },
+  "/biblios/{biblio_id}/checkouts": {
+    "get": {
+      "x-mojo-to": "Biblios#get_checkouts",
+      "operationId": "listBiblioCheckouts",
+      "tags": [
+        "checkouts"
+      ],
+      "summary": "List checkouts for a biblio",
+      "parameters": [
+        {
+          "$ref": "../parameters.json#/biblio_id_pp"
+        },
+        {
+          "$ref": "../parameters.json#/page"
+        },
+        {
+          "$ref": "../parameters.json#/per_page"
+        },
+        {
+          "$ref": "../parameters.json#/match"
+        },
+        {
+          "$ref": "../parameters.json#/order_by"
+        },
+        {
+          "$ref": "../parameters.json#/q_param"
+        },
+        {
+          "$ref": "../parameters.json#/q_body"
+        },
+        {
+          "$ref": "../parameters.json#/q_header"
+        },
+        {
+          "name": "checked_in",
+          "in": "query",
+          "description": "By default, current checkouts are returned, when this is true then checked in checkouts are returned as result.",
+          "type": "boolean"
+        }
+      ],
+      "produces": [
+        "application/json"
+      ],
+      "responses": {
+        "200": {
+          "description": "A list of checkouts",
+          "schema": {
+            "$ref": "../definitions.json#/checkouts"
+          }
+        },
+        "403": {
+          "description": "Access forbidden",
+          "schema": {
+            "$ref": "../definitions.json#/error"
+          }
+        },
+        "404": {
+          "description": "Biblio not found",
+          "schema": {
+            "$ref": "../definitions.json#/error"
+          }
+        }
+      },
+      "x-koha-authorization": {
+        "permissions": {
+          "circulate": "circulate_remaining_permissions"
+        }
+      },
+      "x-koha-embed": [
+        "issuer",
+        "item",
+        "patron",
+        "library"
+      ]
+    }
+  },
   "/biblios/{biblio_id}/items": {
     "get": {
       "x-mojo-to": "Biblios#get_items",
diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json
index e79a5db01d..d16387b9c5 100644
--- a/api/v1/swagger/paths/checkouts.json
+++ b/api/v1/swagger/paths/checkouts.json
@@ -15,7 +15,13 @@
         "$ref": "../parameters.json#/match"
       }, {
         "$ref": "../parameters.json#/order_by"
-      },{
+      }, {
+        "$ref": "../parameters.json#/q_param"
+      }, {
+        "$ref": "../parameters.json#/q_body"
+      }, {
+        "$ref": "../parameters.json#/q_header"
+      }, {
         "name": "checked_in",
         "in": "query",
         "description": "By default, current checkouts are returned, when this is true then checked in checkouts are returned as result.",
-- 
2.20.1