Bug 36562

Summary: Add GET endpoint for counting checkouts
Product: Koha Reporter: Alex Arnaud <alex.arnaud>
Component: REST APIAssignee: Bugs List <koha-bugs>
Status: CLOSED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, lucas, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 36562: [REST API] Add GET endpoint for counting checkouts

Description Alex Arnaud 2024-04-10 07:05:34 UTC
Currently we can paginate checkouts using REST API. It could be useful to have the count only to prepare showing a paginated result.
Comment 1 Alex Arnaud 2024-04-10 07:34:57 UTC
Created attachment 164578 [details] [review]
Bug 36562: [REST API] Add GET endpoint for counting checkouts

Test plan:

curl -v -s -u koha:koha --request GET http://kohadev.local/api/v1/checkouts/count?patron_id=1

Available parameters and permissions are the same than for listing
checkouts
Comment 2 Tomás Cohen Arazi (tcohen) 2024-04-10 12:19:42 UTC
The way to do this, is to perform a:

curl -v -s -u koha:koha --request GET http://kohadev.local/api/v1/checkouts?q={"patron_id":1}&_per_page=1&_page_1

and read the X-Total-Count header from the response.

I was about to point you to the http-client.js library, but it seems the .count method hasn't been ported from the Vue counterpart. Look at the Vue one for more information.

Adding Jonathan, maybe he can comment on why that's not there.
Comment 3 Tomás Cohen Arazi (tcohen) 2024-04-10 12:29:35 UTC
Another option would be to add

    - +strings
+    - checkouts+count
    - extended_attributes

to the 'x-koha-embed' definition for GET /patrons/:patron_id. This is already done in GET /patrons so should work out of the box with that simple spec change.
Comment 4 Jonathan Druart 2024-04-17 09:02:59 UTC
The correct way here is to have GET /patrons/{patron_id}/checkouts and read the X-Total-Count and X-Base-Total-Count headers.