use C4::Context;
use C4::Circulation;
use Koha::Checkouts;
+use Koha::IssuingRules;
use Try::Tiny;
);
}
-sub renewability {
+=head3 allows_renewal
+
+Checks if the checkout could be renewed and return the related information.
+
+=cut
+
+sub allows_renewal {
my $c = shift->openapi->valid_input or return;
my $checkout_id = $c->validation->param('checkout_id');
my $renewable = Mojo::JSON->false;
$renewable = Mojo::JSON->true if $can_renew;
+
+ my $rule = Koha::IssuingRules->get_effective_issuing_rule(
+ {
+ categorycode => $checkout->patron->categorycode,
+ itemtype => $checkout->item->effective_itemtype,
+ branchcode => $checkout->branchcode,
+ }
+ );
return $c->render(
status => 200,
- openapi => { renewable => $renewable, error => $error }
+ openapi => {
+ allows_renewal => $renewable,
+ max_renewals => $rule->renewalsallowed,
+ current_renewals => $checkout->renewals,
+ error => $error
+ }
);
}
"patron_balance": {
"$ref": "definitions/patron_balance.json"
},
- "renewability": {
- "$ref": "definitions/renewability.json"
+ "allows_renewal": {
+ "$ref": "definitions/allows_renewal.json"
},
"vendor": {
"$ref": "definitions/vendor.json"
--- /dev/null
+{
+ "type": "object",
+ "properties": {
+ "allows_renewal": {
+ "type": "boolean",
+ "description": "Renewability status; true = renewable, false = not renewable"
+ },
+ "max_renewals": {
+ "type": "integer",
+ "description": "Maximum number of possible renewals"
+ },
+ "current_renewals": {
+ "type": "integer",
+ "description": "Current used renewals"
+ },
+ "error": {
+ "type": ["string", "null"],
+ "description": "Description on false allows_renewal."
+ }
+ }
+}
+++ /dev/null
-{
- "type": "object",
- "properties": {
- "renewable": {
- "type": "boolean",
- "description": "Renewability status; true = renewable, false = not renewable"
- },
- "error": {
- "type": ["string", "null"],
- "description": "Description on false renewability."
- }
- }
-}
"/libraries/{library_id}": {
"$ref": "paths/libraries.json#/~1libraries~1{library_id}"
},
- "/checkouts/{checkout_id}/renewability": {
- "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewability"
+ "/checkouts/{checkout_id}/allows_renewal": {
+ "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1allows_renewal"
},
"/patrons": {
"$ref": "paths/patrons.json#/~1patrons"
}
}
},
- "/checkouts/{checkout_id}/renewability": {
+ "/checkouts/{checkout_id}/allows_renewal": {
"get": {
- "x-mojo-to": "Checkout#renewability",
- "operationId": "renewabilityCheckout",
+ "x-mojo-to": "Checkouts#allows_renewal",
+ "operationId": "allows_renewalCheckout",
"tags": ["patrons", "checkouts"],
"parameters": [{
- "$ref": "../parameters.json#/checkoutIdPathParam"
+ "$ref": "../parameters.json#/checkout_id_pp"
}],
"produces": ["application/json"],
"responses": {
"200": {
- "description": "Checkout renewability",
- "schema": { "$ref": "../definitions.json#/renewability" }
+ "description": "Checkout renewability information",
+ "schema": { "$ref": "../definitions.json#/allows_renewal" }
},
"403": {
"description": "Forbidden",
required_permissions => { circulate => "circulate_remaining_permissions" }
});
-$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
+$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/allows_renewal")
->status_is(200)
- ->json_is({ renewable => Mojo::JSON->true, error => undef });
+ ->json_is({
+ allows_renewal => Mojo::JSON->true,
+ max_renewals => 1,
+ current_renewals => 0,
+ error => undef
+ });
$t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewal" )
->status_is(201)
->status_is(403)
->json_is({ error => 'Renewal not authorized (too_many)' });
-$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
+$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/allows_renewal")
->status_is(200)
- ->json_is({ renewable => Mojo::JSON->false, error => 'too_many' });
+ ->json_is({
+ allows_renewal => Mojo::JSON->false,
+ max_renewals => 1,
+ current_renewals => 1,
+ error => 'too_many'
+ });