From 93961e8654ca361a4e7db754f752312f601e53d3 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` --- Koha/REST/V1/Checkouts.pm | 36 ++++++++++++++++++++++ api/v1/swagger/definitions.yaml | 2 ++ api/v1/swagger/definitions/renewal.yaml | 25 +++++++++++++++ api/v1/swagger/paths.yaml | 2 ++ api/v1/swagger/paths/checkouts.yaml | 41 +++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 api/v1/swagger/definitions/renewal.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.yaml b/api/v1/swagger/definitions.yaml index 6bdfea0929..90e81d3cef 100644 --- a/api/v1/swagger/definitions.yaml +++ b/api/v1/swagger/definitions.yaml @@ -51,6 +51,8 @@ patron_extended_attribute: $ref: definitions/patron_extended_attribute.yaml quote: $ref: definitions/quote.yaml +renewal: + $ref: definitions/renewal.yaml return_claim: $ref: definitions/return_claim.yaml smtp_server: diff --git a/api/v1/swagger/definitions/renewal.yaml b/api/v1/swagger/definitions/renewal.yaml new file mode 100644 index 0000000000..1cb50d470a --- /dev/null +++ b/api/v1/swagger/definitions/renewal.yaml @@ -0,0 +1,25 @@ +--- +type: object +properties: + renewal_id: + type: integer + description: internally assigned renewal identifier + checkout_id: + type: integer + description: internally assigned checkout identifier + 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 + renewer: + type: + - object + - "null" + description: The object representing the renewal issuer +additionalProperties: false diff --git a/api/v1/swagger/paths.yaml b/api/v1/swagger/paths.yaml index 6908fa8bb1..d7d9790055 100644 --- a/api/v1/swagger/paths.yaml +++ b/api/v1/swagger/paths.yaml @@ -29,6 +29,8 @@ $ref: paths/checkouts.yaml#/~1checkouts "/checkouts/{checkout_id}": $ref: paths/checkouts.yaml#/~1checkouts~1{checkout_id} +"/checkouts/{checkout_id}/renewals": + $ref: paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewals "/checkouts/{checkout_id}/renewal": $ref: paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal /circulation-rules/kinds: diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml index c90204fdb4..6d76c7444b 100644 --- a/api/v1/swagger/paths/checkouts.yaml +++ b/api/v1/swagger/paths/checkouts.yaml @@ -91,6 +91,7 @@ circulate: circulate_remaining_permissions x-koha-embed: - issuer + - renewals "/checkouts/{checkout_id}/renewal": post: x-mojo-to: Checkouts#renew @@ -130,6 +131,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