From 5e138869dcf7fd17c601fa6950dc5404651bac87 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 26 Feb 2025 11:12:28 +0000 Subject: [PATCH] Bug 39320: Preparation: ERM counts API endpoint Required for the follow-up ERMCounts widget --- Koha/REST/V1/ERM.pm | 37 ++++++++++++++++++ api/v1/swagger/definitions/erm_counts.yaml | 7 ++++ api/v1/swagger/paths/erm_counts.yaml | 38 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 7 ++++ .../prog/js/fetch/erm-api-client.js | 9 +++++ 5 files changed, 98 insertions(+) create mode 100644 api/v1/swagger/definitions/erm_counts.yaml create mode 100644 api/v1/swagger/paths/erm_counts.yaml diff --git a/Koha/REST/V1/ERM.pm b/Koha/REST/V1/ERM.pm index 1fe8911cb0a..168dc025815 100644 --- a/Koha/REST/V1/ERM.pm +++ b/Koha/REST/V1/ERM.pm @@ -20,6 +20,12 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; use Koha::Patrons; +use Koha::ERM::Agreements; +use Koha::ERM::Licenses; +use Koha::ERM::Documents; +use Koha::ERM::EHoldings::Titles; +use Koha::ERM::EHoldings::Packages; +use Koha::ERM::EUsage::UsageDataProviders; use Try::Tiny qw( catch try ); @@ -52,6 +58,37 @@ sub config { ); } +=head3 counts + +Return the ERM resources counts + +=cut + +sub counts { + my $c = shift->openapi->valid_input or return; + + my $agreements_count = Koha::ERM::Agreements->search->count; + my $documents_count = Koha::ERM::Documents->search->count; + my $eholdings_packages_count = Koha::ERM::EHoldings::Packages->search->count; + my $eholdings_titles_count = Koha::ERM::EHoldings::Titles->search->count; + my $licenses_count = Koha::ERM::Licenses->search->count; + my $usage_data_providers_count = Koha::ERM::EUsage::UsageDataProviders->search->count; + + return $c->render( + status => 200, + openapi => { + counts => { + agreements_count => $agreements_count, + documents_count => $documents_count, + eholdings_packages_count => $eholdings_packages_count, + eholdings_titles_count => $eholdings_titles_count, + licenses_count => $licenses_count, + usage_data_providers_count => $usage_data_providers_count, + } + }, + ); +} + =head3 list_users Return the list of possible ERM users diff --git a/api/v1/swagger/definitions/erm_counts.yaml b/api/v1/swagger/definitions/erm_counts.yaml new file mode 100644 index 00000000000..a47d7dd358c --- /dev/null +++ b/api/v1/swagger/definitions/erm_counts.yaml @@ -0,0 +1,7 @@ +--- +type: object +properties: + counts: + type: object + description: List of ERM resources counts +additionalProperties: false diff --git a/api/v1/swagger/paths/erm_counts.yaml b/api/v1/swagger/paths/erm_counts.yaml new file mode 100644 index 00000000000..dfb91605eed --- /dev/null +++ b/api/v1/swagger/paths/erm_counts.yaml @@ -0,0 +1,38 @@ +--- +/erm/counts: + get: + x-mojo-to: ERM#counts + operationId: getERMcounts + description: This resource returns a list of ERM resources counts + summary: get the ERM counts + tags: + - erm_counts + produces: + - application/json + responses: + 200: + description: The ERM counts + schema: + $ref: "../swagger.yaml#/definitions/erm_counts" + 400: + description: Bad request + schema: + $ref: "../swagger.yaml#/definitions/error" + 403: + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + 500: + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + 503: + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + erm: 1 diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 2a49559e0ce..796f2f1dd42 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -50,6 +50,8 @@ definitions: $ref: ./definitions/desk.yaml edifact_file: $ref: ./definitions/edifact_file.yaml + erm_counts: + $ref: ./definitions/erm_counts.yaml erm_config: $ref: ./definitions/erm_config.yaml erm_agreement: @@ -333,6 +335,8 @@ paths: $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios~1{biblio_id}" /erm/config: $ref: ./paths/erm_config.yaml#/~1erm~1config + /erm/counts: + $ref: ./paths/erm_counts.yaml#/~1erm~1counts /erm/agreements: $ref: ./paths/erm_agreements.yaml#/~1erm~1agreements "/erm/agreements/{agreement_id}": @@ -1184,6 +1188,9 @@ tags: - description: "Manage ERM configuration\n" name: erm_config x-displayName: ERM configuration + - description: "Get ERM resources counts\n" + name: erm_counts + x-displayName: ERM counts - description: "Manage ERM counter files\n" name: erm_counter_files x-displayName: ERM counter files diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/erm-api-client.js index b618e0d672b..49e1bad5964 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/fetch/erm-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/erm-api-client.js @@ -447,6 +447,15 @@ export class ERMAPIClient { }), }; } + + get counts() { + return { + get: () => + this.httpClient.get({ + endpoint: "counts", + }), + }; + } } export default ERMAPIClient; -- 2.39.5