Bugzilla – Attachment 168019 Details for
Bug 36641
Add an endpoint to list circulation rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36641: Add endpoint for fetching circulation rules
Bug-36641-Add-endpoint-for-fetching-circulation-ru.patch (text/plain), 9.00 KB, created by
Martin Renvoize (ashimema)
on 2024-06-24 15:29:08 UTC
(
hide
)
Description:
Bug 36641: Add endpoint for fetching circulation rules
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-06-24 15:29:08 UTC
Size:
9.00 KB
patch
obsolete
>From fcd2de10bf8070df93e4a93b20f13d97c13ef510 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 18 Apr 2024 13:45:55 +0100 >Subject: [PATCH] Bug 36641: Add endpoint for fetching circulation rules > >This patch adds an endpoint for fetching ciruclations rules given the >constraints of the passed parameters. > >We optionally expect item_type, library and patron_category as query >parameters and we return a list of relevant circulation rules pertaining >to that combination of requirements. > >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 | 71 +++++++++++++- > .../swagger/definitions/circ-rule-kind.yaml | 2 +- > api/v1/swagger/paths/circulation-rules.yaml | 32 ------ > api/v1/swagger/paths/circulation_rules.yaml | 98 +++++++++++++++++++ > api/v1/swagger/swagger.yaml | 6 +- > 5 files changed, 172 insertions(+), 37 deletions(-) > delete mode 100644 api/v1/swagger/paths/circulation-rules.yaml > create mode 100644 api/v1/swagger/paths/circulation_rules.yaml > >diff --git a/Koha/REST/V1/CirculationRules.pm b/Koha/REST/V1/CirculationRules.pm >index 636985fba64..9551ad9b03e 100644 >--- a/Koha/REST/V1/CirculationRules.pm >+++ b/Koha/REST/V1/CirculationRules.pm >@@ -21,7 +21,6 @@ use Mojo::Base 'Mojolicious::Controller'; > > use Koha::CirculationRules; > >- > =head1 API > > =head2 Methods >@@ -36,9 +35,77 @@ sub get_kinds { > my $c = shift->openapi->valid_input or return; > > return $c->render( >- status => 200, >+ status => 200, > openapi => Koha::CirculationRules->rule_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 $branchcode = $c->param('library'); >+ my $patron_category = $c->param('category'); >+ my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; >+ >+ if ($item_type) { >+ my $type = Koha::ItemTypes->find($item_type); >+ return $c->render_invalid_parameter_value( >+ { >+ path => '/query/item_type', >+ values => { >+ uri => '/api/v1/item_types', >+ field => 'item_type_id' >+ } >+ } >+ ) unless $type; >+ } >+ >+ if ($branchcode) { >+ my $library = Koha::Libraries->find($branchcode); >+ return $c->render_invalid_parameter_value( >+ { >+ path => '/query/library', >+ values => { >+ uri => '/api/v1/libraries', >+ field => 'library_id' >+ } >+ } >+ ) unless $library; >+ } >+ >+ if ($patron_category) { >+ my $category = Koha::Patron::Categories->find($patron_category); >+ return $c->render_invalid_parameter_value( >+ { >+ path => '/query/patron_category', >+ values => { >+ uri => '/api/v1/patron_categories', >+ field => 'patron_category_id' >+ } >+ } >+ ) unless $category; >+ } >+ >+ my $effective_rules = Koha::CirculationRules->get_effective_rules( >+ { >+ categorycode => $patron_category, >+ itemtype => $item_type, >+ branchcode => $branchcode, >+ rules => $rules >+ } >+ ); >+ >+ return $c->render( >+ status => 200, >+ openapi => $effective_rules >+ ); >+} >+ > 1; >diff --git a/api/v1/swagger/definitions/circ-rule-kind.yaml b/api/v1/swagger/definitions/circ-rule-kind.yaml >index 3a3a766cc83..f4e82088644 100644 >--- a/api/v1/swagger/definitions/circ-rule-kind.yaml >+++ b/api/v1/swagger/definitions/circ-rule-kind.yaml >@@ -10,6 +10,6 @@ properties: > - branchcode > - categorycode > - itemtype >-additionalProperties: false >+additionalProperties: true > required: > - scope >diff --git a/api/v1/swagger/paths/circulation-rules.yaml b/api/v1/swagger/paths/circulation-rules.yaml >deleted file mode 100644 >index 545f15458a9..00000000000 >--- a/api/v1/swagger/paths/circulation-rules.yaml >+++ /dev/null >@@ -1,32 +0,0 @@ >---- >-/circulation-rules/kinds: >- get: >- x-mojo-to: CirculationRules#get_kinds >- operationId: getCirculationRuleKinds >- tags: >- - circulation_rules >- summary: Get circulation rules kinds >- produces: >- - application/json >- responses: >- "200": >- description: A map of rule kind information >- schema: >- type: object >- additionalProperties: >- $ref: "../swagger.yaml#/definitions/circ-rule-kind" >- "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" >diff --git a/api/v1/swagger/paths/circulation_rules.yaml b/api/v1/swagger/paths/circulation_rules.yaml >new file mode 100644 >index 00000000000..95477754db3 >--- /dev/null >+++ b/api/v1/swagger/paths/circulation_rules.yaml >@@ -0,0 +1,98 @@ >+--- >+/circulation_rules: >+ 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: item_type >+ in: query >+ description: The itemtype >+ required: false >+ type: string >+ - name: library >+ in: query >+ description: The library code >+ required: false >+ type: string >+ - name: patron_category >+ in: query >+ description: The patron category >+ required: false >+ type: string >+ - name: rules >+ in: query >+ description: A comma-separated list of rule kinds >+ required: false >+ type: array >+ items: >+ type: string >+ collectionFormat: multi >+ responses: >+ "200": >+ description: A list of rules for this itemtype, library and patron category combination >+ schema: >+ type: object >+ additionalProperties: >+ type: [ 'string', 'integer' ] >+ "400": >+ description: Bad request >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "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 >+/circulation_rules/kinds: >+ get: >+ x-mojo-to: CirculationRules#get_kinds >+ operationId: getCirculationRuleKinds >+ tags: >+ - circulation_rules >+ summary: Get circulation rules kinds >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A map of rule kind information >+ schema: >+ type: object >+ additionalProperties: >+ $ref: "../swagger.yaml#/definitions/circ-rule-kind" >+ "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..e7ff2c60f22 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -279,8 +279,10 @@ paths: > $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal" > "/checkouts/availability": > $ref: "./paths/checkouts.yaml#/~1checkouts~1availability" >- /circulation-rules/kinds: >- $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds >+ /circulation_rules: >+ $ref: ./paths/circulation_rules.yaml#/~1circulation_rules >+ /circulation_rules/kinds: >+ $ref: ./paths/circulation_rules.yaml#/~1circulation_rules~1kinds > /cities: > $ref: ./paths/cities.yaml#/~1cities > "/cities/{city_id}": >-- >2.45.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36641
:
165086
|
167937
|
167938
|
167946
|
167947
|
168018
|
168019
|
168020
|
168023
|
168024
|
168025
|
168365
|
168366
|
168367
|
168368
|
168369
|
168370
|
168378
|
168379
|
168395
|
168396
|
168397
|
168398
|
168399
|
168400
|
168401
|
168841
|
168874
|
168875
|
168876
|
168877
|
168878
|
168879
|
168880
|
168881
|
168882
|
168883
|
168884
|
168905
|
168906
|
168907
|
168908
|
168909
|
168910
|
168911
|
168912
|
168913
|
168914
|
168915
|
168916
|
168926
|
168927
|
168928
|
168929
|
168930
|
168931
|
168932
|
168933
|
168934
|
168935
|
168936
|
168937
|
168938
|
168940
|
169013
|
169014
|
169015
|
169016
|
169017
|
169018
|
169019
|
169020
|
169021
|
169022
|
169023
|
169024
|
169025
|
169026