From e6715471214c02fe5d07f646ce8c362818a8471c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 18 Apr 2024 13:45:55 +0100 Subject: [PATCH] Bug 36641: Add endpoint for fetching circulation rules This patch is a proof of concept for an API endpoint that returns a list of circulation rules for the specified itemtype, branchcode and patron category combination. You can also add a list of `rules` as a query parameter to limit the response to only the rules you are interested in for this combination. --- Koha/REST/V1/CirculationRules.pm | 30 +++++++++++ api/v1/swagger/paths/circulation-rules.yaml | 55 +++++++++++++++++++++ api/v1/swagger/swagger.yaml | 2 + 3 files changed, 87 insertions(+) diff --git a/Koha/REST/V1/CirculationRules.pm b/Koha/REST/V1/CirculationRules.pm index 636985fba64..f692181c0ac 100644 --- a/Koha/REST/V1/CirculationRules.pm +++ b/Koha/REST/V1/CirculationRules.pm @@ -41,4 +41,34 @@ sub get_kinds { ); } + +=head3 list_effective_rules + +List all effective rules for the requested patron/item/branch combination + +=cut + +sub list_effective_rules { + my $c = shift->openapi->valid_input or return; + + my $item_type = $c->param('itemtype'); + my $library = $c->param('library'); + my $patron_category = $c->param('category'); + my $rules = $c->param('rules') // [ keys %{Koha::CirculationRules->rule_kinds} ]; + + my $effective_rules = Koha::CirculationRules->get_effective_rules( + { + categorycode => $patron_category, + itemtype => $item_type, + branchcode => $library, + rules => $rules + } + ); + + return $c->render( + status => 200, + openapi => $effective_rules + ); +} + 1; diff --git a/api/v1/swagger/paths/circulation-rules.yaml b/api/v1/swagger/paths/circulation-rules.yaml index 545f15458a9..742227932d6 100644 --- a/api/v1/swagger/paths/circulation-rules.yaml +++ b/api/v1/swagger/paths/circulation-rules.yaml @@ -30,3 +30,58 @@ description: Under maintenance schema: $ref: "../swagger.yaml#/definitions/error" +/circulation-rules/{itemtype}/{library}/{category}: + get: + x-mojo-to: CirculationRules#list_effective_rules + operationId: listCirculationRules + tags: + - circulation_rules + summary: Get circulation rules for this item/library/patron combination + produces: + - application/json + parameters: + - name: itemtype + in: path + description: The itemtype + required: true + type: string + - name: library + in: path + description: The library code + required: true + type: string + - name: category + in: path + description: The patron category + required: true + type: string + - name: rules + in: query + description: A comma-separated list of rule kinds + type: array + items: + type: string + collectionFormat: csv + responses: + "200": + description: A list of rules for this itemtype, library and patron category combination + schema: + type: object + "403": + description: Access forbidden + 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: + - circulate: circulate_remaining_permissions diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 7352b1c2401..812287bfb63 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -281,6 +281,8 @@ paths: $ref: "./paths/checkouts.yaml#/~1checkouts~1availability" /circulation-rules/kinds: $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds + /circulation-rules/{itemtype}/{library}/{category}: + $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1{itemtype}~1{library}~1{category} /cities: $ref: ./paths/cities.yaml#/~1cities "/cities/{city_id}": -- 2.45.2