Bug 32997 - Add GET endpoint for listing authorised value categories
Summary: Add GET endpoint for listing authorised value categories
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low new feature (vote)
Assignee: Pedro Amorim
QA Contact:
URL:
Keywords:
Depends on: 32981
Blocks: 17390 32983 33235
  Show dependency treegraph
 
Reported: 2023-02-17 15:12 UTC by Pedro Amorim
Modified: 2024-02-13 16:50 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.04


Attachments
Bug 32997: Add REST API endpoint to list authorised values for multiple given categories (7.58 KB, patch)
2023-02-20 16:27 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 32997: Add REST API endpoint to list authorised values for multiple given categories (7.42 KB, patch)
2023-02-23 10:56 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 32997: Add REST API endpoint to list authorised values for multiple given categories (2.15 KB, patch)
2023-02-23 14:37 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 32997: Add tests (2.07 KB, patch)
2023-02-24 11:35 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 32997: Add REST API endpoint to list authorised values for multiple given categories (7.47 KB, patch)
2023-02-24 15:41 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 32997: Add tests (2.12 KB, patch)
2023-02-24 15:41 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 32997: (QA follow-up) values => authorised_values (4.60 KB, patch)
2023-03-02 14:46 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Amorim 2023-02-17 15:12:31 UTC
Bug 32981 adds the possibility of retrieving AV's given a category in the api.
Currently, in ERM for example, 11 different AV categories are used, so 11 requests are necessary. Even if lazy-loaded, these are too many requests.

Would be cool to have an AV api endpoint that accepts a list of AV codes and retrieves the values of the codes provided.

Essentially doing what 32981 does but for multiple codes.
Comment 1 Tomás Cohen Arazi 2023-02-17 15:41:22 UTC
Hi, what we need is:

GET /av_categories?q={"av_category_id":["av_1",...,"av_n"]}
x-koha-embed: authorised_values:string

The caveat about :string is that Jonathan is proposing on bug 32981 to return the full AV objects on the avs endpoint. But if the embed didn't include :string and only did the usual thing for embedding related objects, it would be good enough.


Note: the idea behind :string is that it would 'calculate the right strings according to the context' (e.g. public? just the description for a dropdown?) but I don't have a clear idea for this particular use case so I'd move forward with what I proposed, without :string.
Comment 2 Pedro Amorim 2023-02-20 16:27:20 UTC Comment hidden (obsolete)
Comment 3 Jonathan Druart 2023-02-21 08:18:59 UTC
 11     parameters:
 12       - name: category_names
 13         in: query
 14         description: Case insensitive search on category name
 15         required: false
 16         type: array
 17       - name: x-koha-embed

You have an extra 's' here, it should be category_name, or maybe even just 'name' (and add the mapping to Koha::AuthorisedValueCategory->to_api_mapping).
Comment 4 Pedro Amorim 2023-02-23 10:56:33 UTC
Created attachment 147224 [details] [review]
Bug 32997: Add REST API endpoint to list authorised values for multiple given categories

This patch adds /api/v1/authorised_value_categories endpoint that
retrieves authorised value categories for the given names and their
authorised values if x-koha-embed: authorised_values is also given.

To test:
Apply patch
curl -u koha:koha --request GET \"http://localhost:8081/api/v1/authorised_value_categories?q=%7B%22me.category_name%22%3A%5B%22LOC%22%2C%22YES_NO%22%5D%7D\" --header \"x-koha-embed:authorised_values\"
Comment 5 Pedro Amorim 2023-02-23 10:58:34 UTC
(In reply to Jonathan Druart from comment #3)
>  11     parameters:
>  12       - name: category_names
>  13         in: query
>  14         description: Case insensitive search on category name
>  15         required: false
>  16         type: array
>  17       - name: x-koha-embed
> 
> You have an extra 's' here, it should be category_name, or maybe even just
> 'name' (and add the mapping to
> Koha::AuthorisedValueCategory->to_api_mapping).

Actually, I don't think that parameter is needed at all, since the category names are going into the query (q) param, correct?
Tested it and provided a new patch with it removed.
Comment 6 Pedro Amorim 2023-02-23 14:37:59 UTC Comment hidden (obsolete)
Comment 7 Pedro Amorim 2023-02-24 11:35:23 UTC
Created attachment 147296 [details] [review]
Bug 32997: Add tests

Commit message fix
Comment 8 Nick Clemens 2023-02-24 15:41:13 UTC
Created attachment 147340 [details] [review]
Bug 32997: Add REST API endpoint to list authorised values for multiple given categories

This patch adds /api/v1/authorised_value_categories endpoint that
retrieves authorised value categories for the given names and their
authorised values if x-koha-embed: authorised_values is also given.

To test:
Apply patch
curl -u koha:koha --request GET \"http://localhost:8081/api/v1/authorised_value_categories?q=%7B%22me.category_name%22%3A%5B%22LOC%22%2C%22YES_NO%22%5D%7D\" --header \"x-koha-embed:authorised_values\"

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 9 Nick Clemens 2023-02-24 15:41:15 UTC
Created attachment 147341 [details] [review]
Bug 32997: Add tests

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 10 Tomás Cohen Arazi 2023-03-02 14:46:57 UTC
Created attachment 147640 [details] [review]
Bug 32997: (QA follow-up) values => authorised_values

This patch renames that for consistency, and also makes use of the
->authorised_values accessor on the category.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 11 Tomás Cohen Arazi 2023-03-02 14:59:45 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 12 Matt Blenkinsop 2023-03-03 12:13:45 UTC
Nice work everyone!

Pushed to stable for 22.11.x
Comment 13 Lucas Gass 2023-03-10 14:54:27 UTC
Enhancement will not be backported to 22.05.x
Comment 14 Caroline Cyr La Rose 2023-05-24 19:46:06 UTC
Back end stuff, doesn't affect the end user so there's nothing to add/amend in the manual.

I'm told the API docs is automated, so there's no need to put those bugs as Needs documenting.