Bug 22440: ILL API changes
* Add GET /illbackends/{id}/statuses * Change API route to ill/requests Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
33084fb40c
commit
313ce33b22
7 changed files with 136 additions and 18 deletions
|
@ -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
|
||||
|
|
19
api/v1/swagger/definitions/ill_status.yaml
Normal file
19
api/v1/swagger/definitions/ill_status.yaml
Normal file
|
@ -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
|
5
api/v1/swagger/definitions/ill_statuses.yaml
Normal file
5
api/v1/swagger/definitions/ill_statuses.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: array
|
||||
items:
|
||||
$ref: "ill_status.yaml"
|
||||
additionalProperties: false
|
|
@ -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"
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
/ill_requests:
|
||||
/ill/requests:
|
||||
get:
|
||||
x-mojo-to: Illrequests#list
|
||||
operationId: listIllrequests
|
|
@ -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:
|
||||
|
@ -241,14 +245,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:
|
||||
|
@ -785,10 +789,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
|
||||
|
|
|
@ -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(
|
||||
'<option value="">'+ill_all_statuses+'</option>'
|
||||
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue