From f0700ff2c6143de768c91e84a22f09c22c29f68f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 11 Mar 2022 14:05:25 +0000 Subject: [PATCH] Bug 30275: Add `/api/v1/checkouts/{checkout_id}/renewals` Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Checkouts.pm | 36 +++++++++++++++++++++ api/v1/swagger/definitions/renewal.yaml | 33 +++++++++++++++++++ api/v1/swagger/definitions/renewals.yaml | 5 +++ api/v1/swagger/paths/checkouts.yaml | 41 ++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 api/v1/swagger/definitions/renewal.yaml create mode 100644 api/v1/swagger/definitions/renewals.yaml diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm index b00469879a..e4a52b4cad 100644 --- a/Koha/REST/V1/Checkouts.pm +++ b/Koha/REST/V1/Checkouts.pm @@ -99,6 +99,42 @@ sub get { }; } +=head3 get_renewals + +List Koha::Checkout::Renewals + +=cut + +sub get_renewals { + my $c = shift->openapi->valid_input or return; + + try { + my $checkout_id = $c->validation->param('checkout_id'); + my $checkout = Koha::Checkouts->find($checkout_id); + $checkout = Koha::Old::Checkouts->find($checkout_id) + unless ($checkout); + + unless ($checkout) { + return $c->render( + status => 404, + openapi => { error => "Checkout doesn't exist" } + ); + } + + my $renewals_rs = $checkout->renewals; + my $renewals = $c->objects->search( $renewals_rs ); + + return $c->render( + status => 200, + openapi => $renewals + ); + } + catch { + $c->unhandled_exception($_); + }; +} + + =head3 renew Renew a checkout diff --git a/api/v1/swagger/definitions/renewal.yaml b/api/v1/swagger/definitions/renewal.yaml new file mode 100644 index 0000000000..97d50ea7f6 --- /dev/null +++ b/api/v1/swagger/definitions/renewal.yaml @@ -0,0 +1,33 @@ +--- +type: object +properties: + renewal_id: + type: integer + description: internally assigned renewal identifier + checkout_id: + type: integer + description: internally assigned checkout identifier + interface: + type: + - string + - "null" + description: "Interface from which the renewal took place (values can be: api, cron, commandline, intranet, opac and sip)" + renewer_id: + $ref: ../x-primitives.yaml#/patron_id + renewal_date: + type: string + format: date-time + description: Date the renewal took place + seen: + type: + - boolean + description: Seen/Unseen renewal + timestamp: + type: string + description: Last update time + renewer: + type: + - object + - "null" + description: The object representing the renewal issuer +additionalProperties: false diff --git a/api/v1/swagger/definitions/renewals.yaml b/api/v1/swagger/definitions/renewals.yaml new file mode 100644 index 0000000000..5b2bff0270 --- /dev/null +++ b/api/v1/swagger/definitions/renewals.yaml @@ -0,0 +1,5 @@ +--- +type: array +items: + $ref: renewal.yaml +additionalProperties: false diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml index 8802334d14..7caf1fdffc 100644 --- a/api/v1/swagger/paths/checkouts.yaml +++ b/api/v1/swagger/paths/checkouts.yaml @@ -78,6 +78,7 @@ type: string enum: - issuer + - renewals collectionFormat: csv produces: - application/json @@ -147,6 +148,46 @@ x-koha-authorization: permissions: circulate: circulate_remaining_permissions +"/checkouts/{checkout_id}/renewals": + get: + x-mojo-to: Checkouts#get_renewals + operationId: getRenewals + tags: + - checkouts + summary: List renewals for a checkout + parameters: + - $ref: ../parameters.yaml#/checkout_id_pp + produces: + - application/json + responses: + "200": + description: List of checkouts renewals + schema: + $ref: ../definitions.yaml#/renewal + "403": + description: Access forbidden + schema: + $ref: ../definitions.yaml#/error + "404": + description: Checkout not found + schema: + $ref: ../definitions.yaml#/error + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: ../definitions.yaml#/error + "503": + description: Under maintenance + schema: + $ref: ../definitions.yaml#/error + x-koha-authorization: + permissions: + circulate: circulate_remaining_permissions + x-koha-embed: + - renewer "/checkouts/{checkout_id}/allows_renewal": get: x-mojo-to: Checkouts#allows_renewal -- 2.20.1