Bug 37253 - Enhance POST /checkouts endpoint to accept barcode or item_id
Summary: Enhance POST /checkouts endpoint to accept barcode or item_id
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Jan Kissig
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords: release-notes-needed
Depends on:
Blocks:
 
Reported: 2024-07-04 08:43 UTC by Jan Kissig
Modified: 2024-10-25 09:12 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00
Circulation function:


Attachments
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id (4.06 KB, patch)
2024-07-04 12:13 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id (4.16 KB, patch)
2024-07-04 15:41 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 37253: Tidy changes (1.92 KB, patch)
2024-07-04 15:41 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 37253: Tidy changes (1.90 KB, patch)
2024-10-21 09:14 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id (4.14 KB, patch)
2024-10-21 09:17 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 37253: Tidy changes (1.90 KB, patch)
2024-10-21 09:17 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id (3.72 KB, patch)
2024-10-21 12:44 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id (5.24 KB, patch)
2024-10-22 13:27 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id (5.29 KB, patch)
2024-10-22 13:28 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kissig 2024-07-04 08:43:27 UTC
By now a new checkout is built at least by params patron_id and item_id.

This makes it a bit difficult if you only have a barcode of the item available, f.e. from RFID middleware applications, as you have to make another API call to retrieve the item_id for a barcode first.

I would propose to enhance the POST /checkouts (addCheckout) route to accept either item_id or barcode (external_id in API) as JSON params.
Comment 1 Jan Kissig 2024-07-04 12:13:00 UTC
Created attachment 168503 [details] [review]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id

This patch adds external_id as a body param in POST /checkouts which acts as the items barcode.
This enhances the checkouts route to checkout items directly via barcode which could be useful for external
tools like Koha Offline Circulation Tool

Test plan:

a) apply patch
b) enable system preference RESTBasicAuth
c) check out an item via an API testing tool. Be sure that item is not checked out already.

   Auth: username: koha  &  password: koha
   Body JSON:
   {
     "external_id" : "39999000011418",
     "library_id": "CPL"
   }
   POST http://localhost:8081/api/v1/checkouts
d) check response code 201 and response content
Comment 2 Matt Blenkinsop 2024-07-04 15:41:08 UTC
Created attachment 168507 [details] [review]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id

This patch adds external_id as a body param in POST /checkouts which acts as the items barcode.
This enhances the checkouts route to checkout items directly via barcode which could be useful for external
tools like Koha Offline Circulation Tool

Test plan:

a) apply patch
b) enable system preference RESTBasicAuth
c) check out an item via an API testing tool. Be sure that item is not checked out already.

   Auth: username: koha  &  password: koha
   Body JSON:
   {
     "external_id" : "39999000011418",
     "library_id": "CPL",
     "patron_id": 5
   }
   POST http://localhost:8081/api/v1/checkouts
d) check response code 201 and response content

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 3 Matt Blenkinsop 2024-07-04 15:41:12 UTC
Created attachment 168508 [details] [review]
Bug 37253: Tidy changes

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 4 Matt Blenkinsop 2024-07-04 15:42:05 UTC
All works fine, just amended the test plan to include a patron_id and tidied a few lines to satisfy the QA tests
Comment 5 Jan Kissig 2024-07-04 18:26:05 UTC
(In reply to Matt Blenkinsop from comment #4)
> All works fine, just amended the test plan to include a patron_id 

how could I miss that :/

> and tidied a few lines to satisfy the QA tests

thx
Comment 6 Kyle M Hall (khall) 2024-10-18 15:05:45 UTC
	* Proving /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t KO!

    #   Failed test '201 Created'
    #   at /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t line 495.
     #          got: '400'
    #     expected: '201'
     # Looks like you failed 1 test of 12.

#   Failed test 'add checkout'
#   at /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t line 555.
 # Looks like you failed 1 test of 108.
 /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t ..
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/108 subtests

Test Summary Report
-------------------
 /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t (Wstat: 256 (exited 1) Tests: 108 Failed: 1)
   Failed test:   108
  Non-zero exit status: 1
Files=1, Tests=108,  4 wallclock secs ( 0.01 usr  0.00 sys +  3.38 cusr  0.21 csys =  3.60 CPU)
 Result: FAIL
Comment 7 Jan Kissig 2024-10-18 18:32:47 UTC
(In reply to Kyle M Hall (khall) from comment #6)
> 	* Proving /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t KO!
> 
>     #   Failed test '201 Created'
>     #   at /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t line 495.
>      #          got: '400'
>     #     expected: '201'
>      # Looks like you failed 1 test of 12.
> 
> #   Failed test 'add checkout'
> #   at /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t line 555.
>  # Looks like you failed 1 test of 108.
>  /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t ..
> Dubious, test returned 1 (wstat 256, 0x100)
> Failed 1/108 subtests
> 
> Test Summary Report
> -------------------
>  /kohadevbox/koha/t/db_dependent/api/v1/checkouts.t (Wstat: 256 (exited 1)
> Tests: 108 Failed: 1)
>    Failed test:   108
>   Non-zero exit status: 1
> Files=1, Tests=108,  4 wallclock secs ( 0.01 usr  0.00 sys +  3.38 cusr 
> 0.21 csys =  3.60 CPU)
>  Result: FAIL

hey Kyle, did you run yarn build after applying the patch?
Comment 8 Tomás Cohen Arazi (tcohen) 2024-10-18 18:51:55 UTC
Hi, I'd like to point out we should accept one of them but not both. If we accepted both, then we should check they belong to the same item!

The two consecutive if+find look weird in the sense of the paragraph above.

I had to deal with a similar situation in Koha/REST/V1/Auth/Password.pm:55
Comment 9 Jan Kissig 2024-10-21 09:14:46 UTC
Created attachment 173014 [details] [review]
Bug 37253: Tidy changes

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 10 Jan Kissig 2024-10-21 09:17:34 UTC
Created attachment 173015 [details] [review]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id

This patch adds external_id as a body param in POST /checkouts which acts as the items barcode.
This enhances the checkouts route to checkout items directly via barcode which could be useful for external
tools like Koha Offline Circulation Tool

Test plan:

a) apply patch
b) enable system preference RESTBasicAuth
c) check out an item via an API testing tool. Be sure that item is not checked out already.

   Auth: username: koha  &  password: koha
   Body JSON:
   {
     "external_id" : "39999000011418",
     "library_id": "CPL",
     "patron_id": 5
   }
   POST http://localhost:8081/api/v1/checkouts
d) check response code 201 and response content

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 11 Jan Kissig 2024-10-21 09:17:37 UTC
Created attachment 173016 [details] [review]
Bug 37253: Tidy changes

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 12 Jan Kissig 2024-10-21 09:23:42 UTC
please ignore last 2 patches a I am struggling with git
Comment 13 Jan Kissig 2024-10-21 12:44:52 UTC
Created attachment 173047 [details] [review]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id

This patch adds external_id as a body param in POST /checkouts which acts as the items barcode.
This enhances the checkouts route to checkout items directly via barcode which could be useful for external
tools like Koha Offline Circulation Tool.

When item_id and external_id are given a check is performed that both identifiers  belong to the same item.

Test plan:

a) apply patch
b) enable system preference RESTBasicAuth
c) check out an item via an API testing tool. Be sure that item is not checked out already.

   Auth: username: koha  &  password: koha
   Body JSON:
   {
     "external_id" : "39999000011418",
     "library_id": "CPL",
     "patron_id": 5
   }
   POST http://localhost:8081/api/v1/checkouts
d) check response code 201 and response content

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 14 Tomás Cohen Arazi (tcohen) 2024-10-21 13:15:11 UTC
Jan, please rebase against latest main:

```shell
git rebase -i origin/main 
```

and resubmit. If it depends on some other bug please mark it so.
Comment 15 Jan Kissig 2024-10-21 16:07:44 UTC
(In reply to Tomás Cohen Arazi (tcohen) from comment #14)
> Jan, please rebase against latest main:
> 
> ```shell
> git rebase -i origin/main 
> ```
> 
> and resubmit. If it depends on some other bug please mark it so.

I obsoleted the former patches by accident and 'de'obsoleted them. Patch applies now to main
Comment 16 Tomás Cohen Arazi (tcohen) 2024-10-22 13:27:34 UTC
Created attachment 173139 [details] [review]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id

This patch adds external_id as a body param in POST /checkouts which acts as the items barcode.
This enhances the checkouts route to checkout items directly via barcode which could be useful for external
tools like Koha Offline Circulation Tool

Test plan:

a) apply patch
b) enable system preference RESTBasicAuth
c) check out an item via an API testing tool. Be sure that item is not checked out already.

   Auth: username: koha  &  password: koha
   Body JSON:
   {
     "external_id" : "39999000011418",
     "library_id": "CPL",
     "patron_id": 5
   }
   POST http://localhost:8081/api/v1/checkouts
d) check response code 201 and response content

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 17 Tomás Cohen Arazi (tcohen) 2024-10-22 13:28:09 UTC
Created attachment 173140 [details] [review]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id

This patch adds external_id as a body param in POST /checkouts which acts as the items barcode.
This enhances the checkouts route to checkout items directly via barcode which could be useful for external
tools like Koha Offline Circulation Tool

Test plan:

a) apply patch
b) enable system preference RESTBasicAuth
c) check out an item via an API testing tool. Be sure that item is not checked out already.

   Auth: username: koha  &  password: koha
   Body JSON:
   {
     "external_id" : "39999000011418",
     "library_id": "CPL",
     "patron_id": 5
   }
   POST http://localhost:8081/api/v1/checkouts
d) check response code 201 and response content

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 18 Katrin Fischer 2024-10-25 09:12:39 UTC
Pushed for 24.11!

Well done everyone, thank you!