*** Bug 19406 has been marked as a duplicate of this bug. ***
Would love to see work done on this one :). Not really a priority for me, so I'm not planning to develop a solution, but would be interested in testing it.
Created attachment 151109 [details] [review] Bug 24401: REST API: Check-in WIP Updating files to include API endpoints for check-ins Test plan: 1) Apply bug 23336 as there are dependencies in there required for this to work 2) Apply this patch 3) Run unit tests in t/db_dependent/api/v1/checkouts.t 4) Make POST request to http://yourlibrary/api/v1/checkouts with request body containing 'item_id' & 'library_id' properties. - Observe returned data and HTTP code - 201 for item checked in - 403 for check in not allowed - 409 for Item not found - 400 for item not checked out Sponsored-by: Auckland University of Technology
Created attachment 151181 [details] [review] Bug 24401: REST API: Checkin unit test fixes Sponsored-by: Auckland University of Technology
Created attachment 151182 [details] [review] bug 24401 - REST API: Check-in WIP Couple minor fixes to swagger.yaml Sponsored by: Auckland University of Technology
Created attachment 151183 [details] [review] Bug 24401: REST API: Checkin unit test fixes Sponsored-by: Auckland University of Technology
Created attachment 151184 [details] [review] Bug 24401: REST API: Check-in Updating files to include API endpoints for check-ins Test plan: 1) Apply bug 23336 as there are dependencies in there required for this to work 2) Apply this patch 3) Run unit tests in t/db_dependent/api/v1/checkouts.t 4) Make POST request to http://yourlibrary/api/v1/checkouts with request body containing 'item_id' & 'library_id' properties. - Observe returned data and HTTP code - 201 for item checked in - 403 for check in not allowed - 409 for Item not found - 400 for item not checked out Sponsored-by: Auckland University of Technology
The patches for bug 23336 no longer apply - I will retest when that is fixed (I have changed the status for that bug).
Created attachment 152717 [details] [review] Bug 24401: REST API: Check-in Updating files to include API endpoints for check-ins Test plan: 1) Apply bug 23336 as there are dependencies in there required for this to work 2) Apply this patch 3) Run unit tests in t/db_dependent/api/v1/checkouts.t 4) Make POST request to http://yourlibrary/api/v1/checkouts with request body containing 'item_id' & 'library_id' properties. - Observe returned data and HTTP code - 201 for item checked in - 403 for check in not allowed - 409 for Item not found - 400 for item not checked out Sponsored-by: Auckland University of Technology
The patch no longer applies 8-(... Applying: Bug 24401: REST API: Check-in Using index info to reconstruct a base tree... M Koha/REST/V1/Checkouts.pm M api/v1/swagger/paths/checkouts.yaml M api/v1/swagger/swagger.yaml M t/db_dependent/api/v1/checkouts.t Falling back to patching base and 3-way merge... Auto-merging t/db_dependent/api/v1/checkouts.t CONFLICT (content): Merge conflict in t/db_dependent/api/v1/checkouts.t Auto-merging api/v1/swagger/swagger.yaml Auto-merging api/v1/swagger/paths/checkouts.yaml Auto-merging Koha/REST/V1/Checkouts.pm error: Failed to merge in the changes. Patch failed at 0001 Bug 24401: REST API: Check-in
Created attachment 154428 [details] [review] Bug 24401: REST API: Check-in Updating files to include API endpoints for check-ins Test plan: 1) Apply bug 23336 as there are dependencies in there required for this to work 2) Apply this patch 3) Run unit tests in t/db_dependent/api/v1/checkouts.t 4) Make POST request to http://yourlibrary/api/v1/checkouts with request body containing 'item_id' & 'library_id' properties. - Observe returned data and HTTP code - 201 for item checked in - 403 for check in not allowed - 409 for Item not found - 400 for item not checked out Sponsored-by: Auckland University of Technology
Created attachment 154429 [details] [review] Bug 24401: (QA follow-up) Tidy Checkouts.pm This just tidies the API controller to fit current best practice and make the QA script happy.
Created attachment 154430 [details] [review] Bug 24401: (QA follow-up) Remove $c->validation
Created attachment 154431 [details] [review] Bug 24401: (QA follow-up) Fix failing test
Rebased and resolved QA script issues highlighted.. I've not actually tested the code as yet however, so leaving as NSO.
Is delete the best name for this subroutine? Since perl has a delete() would it not be better to call this delete_checkout?
(In reply to Lucas Gass from comment #16) > Is delete the best name for this subroutine? Since perl has a delete() would > it not be better to call this delete_checkout? Delete seems right from a developer point of view, but in terms of Koha terminlogy... why not use checkin?
I had a go at testing (using Postman), but I couldn't get things to work correctly to get the right responses back (reflecting my lack of knowledge about APIs!) I've listed below what I tried and the results I got. I'm sure I am doing something fundamentally wrong here! I'll leave the testing to someone who knows what they are doing! 8-) Postman setup ============= Add a new request, change to POST with the URL http://127.0.0.1:8081/api/v1/checkouts For authorisation, set system preference RESTBasicAuth = Enable, then add koha and koha for type Basic Auth in the Authorization tab in Postman. For the Body tab in Postman, select the raw option and then JSON as the type of input. 201 for item checked in ======================= I couldn't work out the right request to send to check an item in. Added the patron_id for the user checking item in (koha = 51), otherwise got an error ( {"error":"Patron not found","error_code":"PATRON_NOT_FOUND"} ) { "patron_id": "51", "item_id": "578", "library_id": "CPL" } Same as 400 for item not checked out: - If item is checked out, get '412 Precondition Failed' and {"error":"Confirmation error"}. - If the item is not checked out, it returns '201 Created', and the item is checked out. 403 for check in not allowed ============================ Made password invalid, returns '403 Forbidden' (as expected) with message: {"error":"Invalid password","required_permissions":null} { "item_id": "578", "library_id": "CPL" } 409 for Item not found ======================= Used incorrect value for item_id, returns '409 Conflict' with error: {"error":"Item not found","error_code":"ITEM_NOT_FOUND"} { "item_id": "9000", "library_id": "CPL" } 400 for item not checked out ============================ I couldn't work out the right request to send to get this response. I used patron = koha (patron_id = 51) and item = 578. { "patron_id": "51", "item_id": "578", "library_id": "CPL" } Same as 201 for item checked in: - If item is checked out, get '412 Precondition Failed' and {"error":"Confirmation error"}. - If the item is not checked out, it returns '201 Created', and the item is checked out.
Created attachment 156884 [details] [review] Bug 24401: Unit tests
Created attachment 156885 [details] [review] Bug 24401: Add API endpoint to check in items This adds a POST /checkouts/{checkout_id}/checkin/{library_id} endpoint for returning checkouts To test: - Run unit tests in t/db_dependent/api/v1/checkouts.t - Make POST request to http://yourlibrary/api/v1/checkouts/{checkout_id}/checkin/{library_id} where checkout_id is the ID of the checkout you're returning and library_id is the branchcode of the return library - Observe returned data - 400 incorrect params - 403 cannot be returned - 404 missing params - 201 item checked in Sponsored-by: Auckland University of Technology
Getting sha1 fake ancestor error when trying to apply the patch: git bz apply 24401 Bug 24401 - REST API: Check-in 154428 - Bug 24401: REST API: Check-in 154429 - Bug 24401: (QA follow-up) Tidy Checkouts.pm 154430 - Bug 24401: (QA follow-up) Remove $c->validation 154431 - Bug 24401: (QA follow-up) Fix failing test 156884 - Bug 24401: Unit tests 156885 - Bug 24401: Add API endpoint to check in items Apply? [(y)es, (n)o, (i)nteractive] y Applying: Bug 24401: REST API: Check-in Applying: Bug 24401: (QA follow-up) Tidy Checkouts.pm error: sha1 information is lacking or useless (Koha/REST/V1/Checkouts.pm). error: could not build fake ancestor Patch failed at 0001 Bug 24401: (QA follow-up) Tidy Checkouts.pm hint: Use 'git am --show-current-patch=diff' to see the failed patch
Created attachment 168337 [details] [review] Bug 24401: Add API endpoint to checkin items This adds a post /checkin endpoint to return checked out items either by its item_id or by barcode. To test you can use f.e. ThunderClient extension in codium/vscode. Test plan for ktd on main: a) enable system preference RESTBasicAuth b) check out an item and remember its item id or barcode. You can use the checkouts endpoint for this: Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } POST http://localhost:8081/api/v1/checkouts c) apply patch and check in item via new checkin endpoint Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } or { "external_id" : "39999000011418", "library_id": "CPL" } POST http://localhost:8081/api/v1/checkin The endpoint accepts item_id and/or barcode as body params. d) check JSON response for return messages e) run unit tests: prove t/db_dependent/api/v1/checkin.t
I rebuild the whole endpoint to be a simple POST checkin endpoint and therefore obsoleted the older patches which weren't applying anymore. I also obsoleted the patch DELETE /checkouts/{checkout_id}/checkin/{library_id} as I found it quite difficult to use because one had to make several api calls to retrieve that checkout_id. If it is still needed I could open another bug for it. This endpoint could also be used for solving offline circulations with KOCT https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37060
Created attachment 172764 [details] [review] Bug 24401: Add API endpoint to checkin items This adds a post /checkin endpoint to return checked out items either by its item_id or by barcode. To test you can use f.e. ThunderClient extension in codium/vscode. Test plan for ktd on main: a) enable system preference RESTBasicAuth b) check out an item and remember its item id or barcode. You can use the checkouts endpoint for this: Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } POST http://localhost:8081/api/v1/checkouts c) apply patch and check in item via new checkin endpoint Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } or { "external_id" : "39999000011418", "library_id": "CPL" } POST http://localhost:8081/api/v1/checkin The endpoint accepts item_id and/or barcode as body params. d) check JSON response for return messages e) run unit tests: prove t/db_dependent/api/v1/checkin.t Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
Created attachment 173189 [details] [review] Bug 24401: Add API endpoint to checkin items This adds a post /checkin endpoint to return checked out items either by its item_id or barcode. To test you can use f.e. ThunderClient extension in codium/vscode. Test plan for ktd on main: a) enable system preference RESTBasicAuth b) check out an item and remember its item id or barcode. You can use the checkouts endpoint for this: Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } POST http://localhost:8081/api/v1/checkouts c) apply patch and check in item via new checkin endpoint Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } or { "external_id" : "39999000011418", "library_id": "CPL" } POST http://localhost:8081/api/v1/checkin The endpoint accepts item_id and/or barcode as body params. d) check JSON response for return messages e) run unit tests: prove t/db_dependent/api/v1/checkin.t Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
The last patch reflects the advise given in https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37253 , that if an item_id AND a barcode is given they both get checked to belong to the same item
Created attachment 173194 [details] [review] Bug 24401: Add API endpoint to checkin items This adds a post /checkin endpoint to return checked out items either by its item_id or barcode. To test you can use f.e. ThunderClient extension in codium/vscode. Test plan for ktd on main: a) enable system preference RESTBasicAuth b) check out an item and remember its item id or barcode. You can use the checkouts endpoint for this: Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } POST http://localhost:8081/api/v1/checkouts c) apply patch and check in item via new checkin endpoint Auth: username: koha & password: koha Body JSON: { "item_id" : 578, "library_id": "CPL" } or { "external_id" : "39999000011418", "library_id": "CPL" } POST http://localhost:8081/api/v1/checkin The endpoint accepts item_id and/or barcode as body params. d) check JSON response for return messages e) run unit tests: prove t/db_dependent/api/v1/checkin.t Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com> Signed-off-by: David Nind <david@davidnind.com>
Testing notes (using KTD): 1. After applying the patch, run: yarn api:bundle 2. Restart everything: restart_all