Bugzilla – Attachment 173015 Details for
Bug 37253
Enhance POST /checkouts endpoint to accept barcode or item_id
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id
Bug-37253-Enhance-POST-checkouts-endpoint-to-accep.patch (text/plain), 4.14 KB, created by
Jan Kissig
on 2024-10-21 09:17:34 UTC
(
hide
)
Description:
Bug 37253: Enhance POST /checkouts endpoint to accept barcode or item_id
Filename:
MIME Type:
Creator:
Jan Kissig
Created:
2024-10-21 09:17:34 UTC
Size:
4.14 KB
patch
obsolete
>From 73d224c88db257ee6ac75bad8b7c3279d2ba3167 Mon Sep 17 00:00:00 2001 >From: Jan Kissig <jkissig@th-wildau.de> >Date: Thu, 4 Jul 2024 13:37:47 +0200 >Subject: [PATCH] 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> >--- > Koha/REST/V1/Checkouts.pm | 20 +++++++++++++++++++- > api/v1/swagger/definitions/checkout.yaml | 6 +++++- > t/db_dependent/api/v1/checkouts.t | 11 ++++++++--- > 3 files changed, 32 insertions(+), 5 deletions(-) > >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index 301369a45c..f20e61d038 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -189,6 +189,7 @@ sub add { > my $item_id = $body->{item_id}; > my $patron_id = $body->{patron_id}; > my $onsite = $body->{onsite_checkout}; >+ my $barcode = $body->{external_id}; > > if ( $c->stash('is_public') > && !C4::Context->preference('OpacTrustedCheckout') ) >@@ -203,7 +204,24 @@ sub add { > } > > return try { >- my $item = Koha::Items->find($item_id); >+ >+ unless ($item_id or $barcode){ >+ return $c->render( >+ status => 400, >+ openapi => { >+ error => 'Missing or wrong parameters', >+ error_code => 'MISSING_OR_WRONG_PARAMETERS', >+ } >+ ); >+ } >+ >+ my $item; >+ if ($item_id){ >+ $item = Koha::Items->find($item_id); >+ } >+ if ($barcode){ >+ $item = Koha::Items->find({ barcode => $barcode }); >+ } > unless ($item) { > return $c->render( > status => 409, >diff --git a/api/v1/swagger/definitions/checkout.yaml b/api/v1/swagger/definitions/checkout.yaml >index 4a9847623c..4ace091bd5 100644 >--- a/api/v1/swagger/definitions/checkout.yaml >+++ b/api/v1/swagger/definitions/checkout.yaml >@@ -11,7 +11,11 @@ properties: > type: > - integer > - "null" >- description: internal identifier of checked out item >+ external_id: >+ type: >+ - string >+ - "null" >+ description: other identifier of checked out item f.e. barcode > due_date: > type: string > format: date-time >diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t >index 8f306df0e0..38d634bc4d 100755 >--- a/t/db_dependent/api/v1/checkouts.t >+++ b/t/db_dependent/api/v1/checkouts.t >@@ -439,7 +439,7 @@ subtest 'get_availability' => sub { > > subtest 'add checkout' => sub { > >- plan tests => 10; >+ plan tests => 12; > > $schema->storage->txn_begin; > my $librarian = $builder->build_object( >@@ -465,8 +465,9 @@ subtest 'add checkout' => sub { > > my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; > >- my $item1 = $builder->build_sample_item; >- my $item1_id = $item1->id; >+ my $item1 = $builder->build_sample_item; >+ my $item1_id = $item1->id; >+ my $item1_barcode = $item1->barcode; > > my %issuingimpossible = (); > my %needsconfirmation = (); >@@ -491,6 +492,10 @@ subtest 'add checkout' => sub { > $t->post_ok( "//$userid:$password@/api/v1/checkouts" => json => { item_id => $item1_id, patron_id => $patron_id } ) > ->status_is(201); > >+ $t->post_ok( "//$userid:$password@/api/v1/checkouts" => json => { external_id => $item1_barcode, patron_id => $patron_id } ) >+ ->status_is(201); >+ >+ > # Needs confirm > %needsconfirmation = ( confirm1 => 1, confirm2 => 'please' ); > $t->post_ok( >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37253
:
168503
|
168507
|
168508
|
173014
|
173015
|
173016
|
173047
|
173139
|
173140