From aba59e1b59ff98bb968cad2ca391fe33941ea279 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 24 Apr 2023 15:28:28 +0000 Subject: [PATCH] Bug 22440: ILL API changes * Add GET /illbackends/{id}/statuses * Change API route to ill/requests Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 313ce33b22509b2cdb349f1e4bc2793d8d972050) Signed-off-by: Martin Renvoize --- Koha/REST/V1/Illbackends.pm | 44 +++++++++++++++ api/v1/swagger/definitions/ill_status.yaml | 19 +++++++ api/v1/swagger/definitions/ill_statuses.yaml | 5 ++ api/v1/swagger/paths/ill_backends.yaml | 54 +++++++++++++++++-- .../{illrequests.yaml => ill_requests.yaml} | 2 +- api/v1/swagger/swagger.yaml | 24 +++++---- .../intranet-tmpl/prog/js/ill-list-table.js | 6 +-- 7 files changed, 136 insertions(+), 18 deletions(-) create mode 100644 api/v1/swagger/definitions/ill_status.yaml create mode 100644 api/v1/swagger/definitions/ill_statuses.yaml rename api/v1/swagger/paths/{illrequests.yaml => ill_requests.yaml} (99%) diff --git a/Koha/REST/V1/Illbackends.pm b/Koha/REST/V1/Illbackends.pm index cf2e77f301..c3c917ef70 100644 --- a/Koha/REST/V1/Illbackends.pm +++ b/Koha/REST/V1/Illbackends.pm @@ -51,6 +51,50 @@ sub list { return $c->render( status => 200, openapi => \@data ); } +=head3 list_statuses + +Return a list of existing ILL statuses + +=cut + +sub list_statuses { + my $c = shift->openapi->valid_input; + + my $backend_id = $c->validation->param('ill_backend_id'); + + #FIXME: Currently fetching all requests, it'd be great if we could fetch distinct(status). + # Even doing it with distinct status, we need the ILL request object, so that strings_map works and + # the ILL request returns the correct status and info respective to its backend. + my $ill_requests = Koha::Illrequests->search( + {backend => $backend_id}, + # { + # columns => [ qw/status/ ], + # group_by => [ qw/status/ ], + # } + ); + + my @data; + while (my $request = $ill_requests->next) { + my $status_data = $request->strings_map; + + foreach my $status_class ( qw(status_alias status) ){ + if ($status_data->{$status_class}){ + push @data, { + $status_data->{$status_class}->{str} ? (str => $status_data->{$status_class}->{str}) : + $status_data->{$status_class}->{code} ? (str => $status_data->{$status_class}->{code}) : (), + $status_data->{$status_class}->{code} ? (code => $status_data->{$status_class}->{code}) : (), + } + } + } + } + + # Remove duplicate statuses + my %seen; + @data = grep { my $e = $_; my $key = join '___', map { $e->{$_}; } sort keys %$_;!$seen{$key}++ } @data; + + return $c->render( status => 200, openapi => \@data ); +} + =head3 get Get one backend diff --git a/api/v1/swagger/definitions/ill_status.yaml b/api/v1/swagger/definitions/ill_status.yaml new file mode 100644 index 0000000000..b11ea65080 --- /dev/null +++ b/api/v1/swagger/definitions/ill_status.yaml @@ -0,0 +1,19 @@ +--- +type: object +properties: + str: + type: string + description: Internal ILL status display string + code: + type: string + description: Internal ILL status code or av code + type: + type: string + description: This is 'ill_status' or 'av' depending on if coming from backend or authorised values i.e. alias + backend: + type: string + description: The backend in which this status is used + category: + type: string + description: The AV category in which the status aliases exists in +additionalProperties: false diff --git a/api/v1/swagger/definitions/ill_statuses.yaml b/api/v1/swagger/definitions/ill_statuses.yaml new file mode 100644 index 0000000000..ba2daf9447 --- /dev/null +++ b/api/v1/swagger/definitions/ill_statuses.yaml @@ -0,0 +1,5 @@ +--- +type: array +items: + $ref: "ill_status.yaml" +additionalProperties: false diff --git a/api/v1/swagger/paths/ill_backends.yaml b/api/v1/swagger/paths/ill_backends.yaml index 3537c37cca..1a74f8b622 100644 --- a/api/v1/swagger/paths/ill_backends.yaml +++ b/api/v1/swagger/paths/ill_backends.yaml @@ -1,10 +1,10 @@ --- -/ill_backends: +/ill/backends: get: x-mojo-to: Illbackends#list operationId: listIllbackends tags: - - illbackends + - ill_backends summary: List ILL backends parameters: [] produces: @@ -40,12 +40,12 @@ x-koha-authorization: permissions: ill: "1" -"/ill_backends/{ill_backend_id}": +"/ill/backends/{ill_backend_id}": get: x-mojo-to: Illbackends#get operationId: getIllbackends tags: - - illbackends + - ill_backends summary: Get ILL backend parameters: - name: ill_backend_id @@ -86,3 +86,49 @@ x-koha-authorization: permissions: ill: "1" +"/ill/backends/{ill_backend_id}/statuses": + get: + x-mojo-to: Illbackends#list_statuses + operationId: getIllbackendsStatuses + tags: + - ill_backends + summary: Get existing ILL statuses + parameters: + - name: ill_backend_id + in: path + description: ILL backend id/name + required: true + type: string + produces: + - application/json + responses: + "200": + description: A list of existing ILL statuses + schema: + $ref: "../swagger.yaml#/definitions/ill_statuses" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: ILL backends not found + 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: + ill: "1" \ No newline at end of file diff --git a/api/v1/swagger/paths/illrequests.yaml b/api/v1/swagger/paths/ill_requests.yaml similarity index 99% rename from api/v1/swagger/paths/illrequests.yaml rename to api/v1/swagger/paths/ill_requests.yaml index 5e0d016998..3ba3f2ca3c 100644 --- a/api/v1/swagger/paths/illrequests.yaml +++ b/api/v1/swagger/paths/ill_requests.yaml @@ -1,5 +1,5 @@ --- -/ill_requests: +/ill/requests: get: x-mojo-to: Illrequests#list operationId: listIllrequests diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index c2b510e8fd..163888ce0a 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -52,6 +52,10 @@ definitions: $ref: ./definitions/ill_backend.yaml ill_backends: $ref: ./definitions/ill_backends.yaml + ill_status: + $ref: ./definitions/ill_status.yaml + ill_statuses: + $ref: ./definitions/ill_statuses.yaml ill_request: $ref: ./definitions/ill_request.yaml import_batch_profile: @@ -235,14 +239,14 @@ paths: $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1priority" "/holds/{hold_id}/suspension": $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1suspension" - /ill_backends: - $ref: ./paths/ill_backends.yaml#/~1ill_backends - "/ill_backends/{ill_backend_id}": - $ref: "./paths/ill_backends.yaml#/~1ill_backends~1{ill_backend_id}" - /illrequests: - $ref: ./paths/illrequests.yaml#/~1illrequests - /ill_requests: - $ref: ./paths/illrequests.yaml#/~1ill_requests + /ill/backends: + $ref: ./paths/ill_backends.yaml#/~1ill~1backends + "/ill/backends/{ill_backend_id}": + $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}" + "/ill/backends/{ill_backend_id}/statuses": + $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}~1statuses" + /ill/requests: + $ref: ./paths/ill_requests.yaml#/~1ill~1requests "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen": $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen" /import_batch_profiles: @@ -760,10 +764,10 @@ tags: name: holds x-displayName: Holds - description: "Manage ILL module backends\n" - name: illbackends + name: ill_backends x-displayName: ILL backends - description: "Manage ILL requests\n" - name: illrequests + name: ill_requests x-displayName: ILL requests - description: "Manage import batches\n" name: import_batches diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js b/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js index 9b914cf728..174622ad50 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js +++ b/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js @@ -180,7 +180,7 @@ $(document).ready(function() { var ill_requests_table = $("#ill-requests").kohaTable({ "ajax": { - "url": '/api/v1/ill_requests' + "url": '/api/v1/ill/requests' }, "embed": [ '+strings', @@ -430,7 +430,7 @@ $(document).ready(function() { function populateStatusFilter(backend) { $.ajax({ type: "GET", - url: "/api/v1/ill_backends/"+backend+"/statuses", + url: "/api/v1/ill/backends/"+backend+"/statuses", success: function(statuses){ $('#illfilter_status').append( '' @@ -448,7 +448,7 @@ $(document).ready(function() { function populateBackendFilter() { $.ajax({ type: "GET", - url: "/api/v1/ill_backends", + url: "/api/v1/ill/backends", success: function(backends){ backends.sort((a, b) => a.ill_backend_id.localeCompare(b.ill_backend_id)).forEach(function(backend) { $('#illfilter_backend').append( -- 2.39.5