From dce00cc4db0bd5c804fabbb25be8fbdd06fce39d Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 7 Nov 2024 12:08:53 +0000
Subject: [PATCH] Bug 38389: Add subscriptions to vendor endpoint as embed

---
 Koha/Subscription.pm                          | 20 +++++++++
 api/v1/swagger/definitions/subscription.yaml  | 45 +++++++++++++++++++
 api/v1/swagger/definitions/vendor.yaml        |  5 +++
 .../swagger/paths/acquisitions_vendors.yaml   |  1 +
 4 files changed, 71 insertions(+)
 create mode 100644 api/v1/swagger/definitions/subscription.yaml

diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm
index 45d1c09fa0d..d944a211955 100644
--- a/Koha/Subscription.pm
+++ b/Koha/Subscription.pm
@@ -194,6 +194,26 @@ sub get_sharable_info {
     return $sub_mana_info;
 }
 
+=head3 to_api_mapping
+
+This method returns the mapping for representing a Koha::Subscription object
+on the API.
+
+=cut
+
+sub to_api_mapping {
+    return {
+        subscriptionid           => 'id',
+        biblionumber             => 'biblio_id',
+        librarian                => undef,
+        startdate                => 'start_date',
+        aqbooksellerid           => 'vendor_id',
+        aqbudgetid               => 'budget_id',
+        weeklength               => 'length_in_weeks',
+        monthlength              => 'length_in_months',
+        numberlength             => 'length_in_issues',
+    };
+}
 
 =head3 _type
 
diff --git a/api/v1/swagger/definitions/subscription.yaml b/api/v1/swagger/definitions/subscription.yaml
new file mode 100644
index 00000000000..4f51c39d450
--- /dev/null
+++ b/api/v1/swagger/definitions/subscription.yaml
@@ -0,0 +1,45 @@
+---
+type: object
+properties:
+  id:
+    type: integer
+    description: internally assigned subscription identifier
+    readOnly: true
+  biblio_id:
+    type: integer
+    description: Internal identifier for the linked bibliographic record
+  start_date:
+    type:
+      - string
+      - "null"
+    format: date
+    description: Start date of subscription
+  vendor_id:
+    type: integer
+    description: Internal identifier for the vendor
+  cost:
+    type:
+      - number
+      - "null"
+    description: The cost of this subscription
+  budget_id:
+    type:
+      - number
+      - "null"
+    description: Internal identifier for the budget
+  length_in_weeks:
+    type:
+      - number
+      - "null"
+    description: Length of subscription in weeks
+  length_in_months:
+    type:
+      - number
+      - "null"
+    description: Length of subscription in months
+  length_in_issues:
+    type:
+      - number
+      - "null"
+    description: Length of subscription in number of issues
+additionalProperties: false
diff --git a/api/v1/swagger/definitions/vendor.yaml b/api/v1/swagger/definitions/vendor.yaml
index 3bf8a179772..488ee59f4d5 100644
--- a/api/v1/swagger/definitions/vendor.yaml
+++ b/api/v1/swagger/definitions/vendor.yaml
@@ -119,6 +119,11 @@ properties:
     description: List of aliases
     items:
       $ref: "vendor_alias.yaml"
+  subscriptions:
+    type: array
+    description: List of subscriptions
+    items:
+      $ref: "subscription.yaml"
 additionalProperties: false
 required:
   - name
diff --git a/api/v1/swagger/paths/acquisitions_vendors.yaml b/api/v1/swagger/paths/acquisitions_vendors.yaml
index ed817cc2a1d..aaaed8c534b 100644
--- a/api/v1/swagger/paths/acquisitions_vendors.yaml
+++ b/api/v1/swagger/paths/acquisitions_vendors.yaml
@@ -35,6 +35,7 @@
           type: string
           enum:
             - aliases
+            - subscriptions
         collectionFormat: csv
     responses:
       "200":
-- 
2.47.0