Bug 33161: Add +strings support to GET /items and /items/:item_id
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 7 Mar 2023 23:51:35 +0000 (20:51 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 10 Mar 2023 13:20:09 +0000 (10:20 -0300)
commitdab02607028fadc0e8864102a9a59c7e8fb6c775
treed0d3c0035f5c1b0b00aebc2493d63199513e3a6c
parenta2fa4fcc03583ef3e6a6a299b4c0e0f3145ca32d
Bug 33161: Add +strings support to GET /items and /items/:item_id

This patch introduces the `api_strings_mapping` method to the
*Koha::Item* class, and makes the API spec for the following routes:

* GET /items
* GET /items/:item_id
* GET /acquisitions/orders

accept the new `+strings` parameter that can be passed through the
`x-koha-embed` header and was introduced by bug 26635. In the case of
/acquisitions/orders, you will need to use

x-koha-embed: items+strings

I introduce it here to highlight the flebility we introduced with bug
26635.

The `api_strings_mapping` method has its roots on the cool
`columns_to_str` method already present. The main differences:

* It is aware of the `public_read_list` for attributes so no hidden
  information is exposed.
* Attribute names get mapped for consistency with the API (e.g.
  `homebranch` is converted into `home_library_id`, etc).
* The data structure it returns includes information about the source
  for the descriptions (e.g. it it is an authorised value, then `type`
  will be `av`, and the related category information is returned so
  dropdowns and such can be built. The same goes for other types as
 `library`, `item_type` and `call_number_source`.

To test:
1. Apply this patch
2. Reload everything
3. Play with your favourite REST tool (e.g. Postman)
4. Try:
GET http://localhost:8081/api/v1/items
x-koha-embed: +strings
=> SUCCESS: You get a list of items, they include the new _strings
structure, and the contents make sense!
5. Repeat with a specific item:
GET http://localhost:8081/api/v1/items/14
x-koha-embed: +strings
=> SUCCESS: It all makes sense!
6. Sign off :-D

Sponsored-by: Virginia Polytechnic Institute and State University
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Item.pm
Koha/REST/V1/Items.pm
api/v1/swagger/definitions/item.yaml
api/v1/swagger/paths/acquisitions_orders.yaml
api/v1/swagger/paths/items.yaml