Bugzilla – Attachment 150773 Details for
Bug 31798
Add POST endpoint for Items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Bug-31798-follow-up-Tidy-up-and-add-duplicate-barc.patch (text/plain), 2.92 KB, created by
Kyle M Hall (khall)
on 2023-05-05 15:38:48 UTC
(
hide
)
Description:
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2023-05-05 15:38:48 UTC
Size:
2.92 KB
patch
obsolete
>From b5b37a7cbd06c4bebc7a5c346af7286bf07d6c12 Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Tue, 3 Jan 2023 12:12:39 -0300 >Subject: [PATCH] Bug 31798: (follow-up) Tidy up and add duplicate barcode test > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/V1/Biblios.pm | 20 ++++++++------------ > api/v1/swagger/paths/biblios.yaml | 4 ++++ > t/db_dependent/api/v1/biblios.t | 9 ++++++++- > 3 files changed, 20 insertions(+), 13 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index ab70dcc88f..f1198b246a 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -314,24 +314,20 @@ sub add_item { > $item->barcode($barcode); > } > >- if ( defined $item->barcode >- && Koha::Items->search( { barcode => $item->barcode } )->count ) >- { >- return $c->render( >- status => 400, >- openapi => { error => "Barcode not unique" } >- ); >- } >- >- my $storedItem = $item->store; >- $storedItem->discard_changes; >+ $item->store->discard_changes; > > $c->render( > status => 201, >- openapi => $storedItem->to_api >+ openapi => $item->to_api > ); > } > catch { >+ if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Duplicate barcode.' } >+ ); >+ } > $c->unhandled_exception($_); > } > } >diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml >index 08e9a476ac..1506d019aa 100644 >--- a/api/v1/swagger/paths/biblios.yaml >+++ b/api/v1/swagger/paths/biblios.yaml >@@ -437,6 +437,10 @@ > description: Not found > schema: > $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Conflict >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" > "500": > description: | > Internal server error. Possible `error_code` attribute values: >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >index 8b02dad0f4..a28885f2df 100644 >--- a/t/db_dependent/api/v1/biblios.t >+++ b/t/db_dependent/api/v1/biblios.t >@@ -1690,7 +1690,7 @@ subtest 'list() tests' => sub { > }; > > subtest 'add_item() tests' => sub { >- plan tests => 5; >+ plan tests => 7; > > $schema->storage->txn_begin; > >@@ -1735,5 +1735,12 @@ subtest 'add_item() tests' => sub { > ->status_is(201, 'Item created') > ->json_is('/biblio_id', $biblio_id); > >+ my $item = $builder->build_sample_item(); >+ >+ $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { >+ external_id => $item->barcode, >+ }) >+ ->status_is(409, 'Duplicate barcode'); >+ > $schema->storage->txn_rollback; > }; >-- >2.30.2
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 31798
:
144893
|
144894
|
144952
|
144953
|
144956
|
147463
|
147464
|
147655
|
147656
|
147657
|
150598
|
150599
|
150600
|
150771
|
150772
| 150773 |
150774
|
150775