Bugzilla – Attachment 120501 Details for
Bug 24857
Add ability to group items for records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24857: Implement volume related controllers
Bug-24857-Implement-volume-related-controllers.patch (text/plain), 12.12 KB, created by
Kyle M Hall (khall)
on 2021-05-05 13:24:31 UTC
(
hide
)
Description:
Bug 24857: Implement volume related controllers
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2021-05-05 13:24:31 UTC
Size:
12.12 KB
patch
obsolete
>From 82746113257a68ca430966cf3cbb3b8a12e0861b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 3 Feb 2020 15:27:19 -0300 >Subject: [PATCH] Bug 24857: Implement volume related controllers > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> > >Signed-off-by: Rebecca Coert <rcoert@arlingtonva.us> >--- > Koha/REST/V1/Biblios/Volumes.pm | 252 ++++++++++++++++++++++++++ > Koha/REST/V1/Biblios/Volumes/Items.pm | 165 +++++++++++++++++ > 2 files changed, 417 insertions(+) > create mode 100644 Koha/REST/V1/Biblios/Volumes.pm > create mode 100644 Koha/REST/V1/Biblios/Volumes/Items.pm > >diff --git a/Koha/REST/V1/Biblios/Volumes.pm b/Koha/REST/V1/Biblios/Volumes.pm >new file mode 100644 >index 0000000000..a59efd555e >--- /dev/null >+++ b/Koha/REST/V1/Biblios/Volumes.pm >@@ -0,0 +1,252 @@ >+package Koha::REST::V1::Biblios::Volumes; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::Biblio::Volumes; >+ >+use Scalar::Util qw(blessed); >+use Try::Tiny; >+ >+=head1 NAME >+ >+Koha::REST::V1::Biblios::Volumes - Koha REST API for handling volumes (V1) >+ >+=head1 API >+ >+=head2 Methods >+ >+=cut >+ >+=head3 list >+ >+Controller function that handles listing Koha::Biblio::Volume objects >+ >+=cut >+ >+sub list { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $volumes_set = Koha::Biblio::Volumes->new; >+ my $volumes = $c->objects->search( $volumes_set ); >+ return $c->render( >+ status => 200, >+ openapi => $volumes >+ ); >+ } >+ catch { >+ unless ( blessed $_ && $_->can('rethrow') ) { >+ return $c->render( >+ status => 500, >+ openapi => { >+ error => >+ "Something went wrong, check Koha logs for details." >+ } >+ ); >+ } >+ return $c->render( >+ status => 500, >+ openapi => { error => "$_" } >+ ); >+ }; >+} >+ >+=head3 get >+ >+Controller function that handles retrieving a single Koha::Biblio::Volume >+ >+=cut >+ >+sub get { >+ my $c = shift->openapi->valid_input or return; >+ >+ try { >+ my $volume_id = $c->validation->param('volume_id'); >+ my $biblio_id = $c->validation->param('biblio_id'); >+ >+ my $volume = Koha::Biblio::Volumes->find( $volume_id ); >+ my $embed = $c->stash('koha.embed'); >+ >+ if ( $volume && $volume->biblionumber eq $biblio_id ) { >+ return $c->render( >+ status => 200, >+ openapi => $volume->to_api({ embed => $embed }) >+ ); >+ } >+ else { >+ return $c->render( >+ status => 404, >+ openapi => { >+ error => 'Volume not found' >+ } >+ ); >+ } >+ } >+ catch { >+ return $c->render( >+ status => 500, >+ openapi => { >+ error => "Something went wrong, check the logs ($_)." >+ } >+ ); >+ }; >+} >+ >+=head3 add >+ >+Controller function to handle adding a Koha::Biblio::Volume object >+ >+=cut >+ >+sub add { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $volume_data = $c->validation->param('body'); >+ # biblio_id comes from the path >+ $volume_data->{biblio_id} = $c->validation->param('biblio_id'); >+ >+ my $volume = Koha::Biblio::Volume->new_from_api($volume_data); >+ $volume->store->discard_changes(); >+ >+ $c->res->headers->location( $c->req->url->to_string . '/' . $volume->id ); >+ >+ return $c->render( >+ status => 201, >+ openapi => $volume->to_api >+ ); >+ } >+ catch { >+ if ( blessed($_) ) { >+ my $to_api_mapping = Koha::Biblio::Volume->new->to_api_mapping; >+ >+ if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" >+ } >+ ); >+ } >+ } >+ >+ return $c->render( >+ status => 500, >+ openapi => { >+ error => "Unhandled exception ($_)" >+ } >+ ); >+ }; >+} >+ >+=head3 update >+ >+Controller function to handle updating a Koha::Biblio::Volume object >+ >+=cut >+ >+sub update { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $volume_id = $c->validation->param('volume_id'); >+ my $biblio_id = $c->validation->param('biblio_id'); >+ >+ my $volume = Koha::Biblio::Volumes->find( $volume_id ); >+ >+ unless ( $volume && $volume->biblionumber eq $biblio_id ) { >+ return $c->render( >+ status => 404, >+ openapi => { >+ error => 'Volume not found' >+ } >+ ); >+ } >+ >+ my $volume_data = $c->validation->param('body'); >+ $volume->set_from_api( $volume_data )->store->discard_changes(); >+ >+ return $c->render( >+ status => 200, >+ openapi => $volume->to_api >+ ); >+ } >+ catch { >+ if ( blessed($_) ) { >+ my $to_api_mapping = Koha::Biblio::Volume->new->to_api_mapping; >+ >+ if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" >+ } >+ ); >+ } >+ } >+ >+ return $c->render( >+ status => 500, >+ openapi => { >+ error => "Unhandled exception ($_)" >+ } >+ ); >+ }; >+} >+ >+=head3 delete >+ >+Controller function that handles deleting a Koha::Biblio::Volume object >+ >+=cut >+ >+sub delete { >+ >+ my $c = shift->openapi->valid_input or return; >+ >+ my $volume_id = $c->validation->param( 'volume_id' ); >+ my $biblio_id = $c->validation->param( 'biblio_id' ); >+ >+ my $volume = Koha::Biblio::Volumes->find({ id => $volume_id, biblionumber => $biblio_id }); >+ >+ if ( not defined $volume ) { >+ return $c->render( status => 404, openapi => { error => "Volume not found" } ); >+ } >+ >+ return try { >+ $volume->delete; >+ return $c->render( status => 204, openapi => ''); >+ } >+ catch { >+ unless ( blessed $_ && $_->can('rethrow') ) { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check Koha logs for details." } >+ ); >+ } >+ >+ return $c->render( >+ status => 500, >+ openapi => { error => "$_" } >+ ); >+ }; >+} >+ >+1; >diff --git a/Koha/REST/V1/Biblios/Volumes/Items.pm b/Koha/REST/V1/Biblios/Volumes/Items.pm >new file mode 100644 >index 0000000000..0e252f872a >--- /dev/null >+++ b/Koha/REST/V1/Biblios/Volumes/Items.pm >@@ -0,0 +1,165 @@ >+package Koha::REST::V1::Biblios::Volumes::Items; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::Biblio::Volume::Items; >+ >+use Scalar::Util qw(blessed); >+use Try::Tiny; >+ >+=head1 NAME >+ >+Koha::REST::V1::Biblios::Volumes::Items - Koha REST API for handling volume items (V1) >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 add >+ >+Controller function to handle adding a Koha::Biblio::Volume object >+ >+=cut >+ >+sub add { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ >+ my $volume = Koha::Biblio::Volumes->find( >+ $c->validation->param('volume_id') >+ ); >+ >+ unless ( $volume ) { >+ return $c->render( >+ status => 404, >+ openapi => { >+ error => 'Volume not found' >+ } >+ ); >+ } >+ >+ # All good, add the item >+ my $body = $c->validation->param('body'); >+ my $item_id = $body->{item_id}; >+ >+ $volume->add_item({ item_id => $item_id }); >+ >+ $c->res->headers->location( $c->req->url->to_string . '/' . $item_id ); >+ >+ my $embed = $c->stash('koha.embed'); >+ >+ return $c->render( >+ status => 201, >+ openapi => $volume->to_api({ embed => $embed }) >+ ); >+ } >+ catch { >+ if ( blessed($_) ) { >+ >+ if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { >+ if ( $_->broken_fk eq 'itemnumber' ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "Given item_id does not exist" >+ } >+ ); >+ } >+ elsif ( $_->broken_fk eq 'biblionumber' ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "Given item_id does not belong to the volume's biblio" >+ } >+ ); >+ } >+ } >+ elsif ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) { >+ >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "The given item_id is already linked to the volume" >+ } >+ ); >+ } >+ } >+ >+ return $c->render( >+ status => 500, >+ openapi => { >+ error => "Unhandled exception ($_)" >+ } >+ ); >+ }; >+} >+ >+=head3 delete >+ >+Controller function that handles deleting a Koha::Biblio::Volume object >+ >+=cut >+ >+sub delete { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $volume_id = $c->validation->param('volume_id'); >+ my $item_id = $c->validation->param('item_id'); >+ >+ my $item_link = Koha::Biblio::Volume::Items->find( >+ { >+ itemnumber => $item_id, >+ volume_id => $volume_id >+ } >+ ); >+ >+ unless ( $item_link ) { >+ return $c->render( >+ status => 404, >+ openapi => { >+ error => 'No such volume <-> item relationship' >+ } >+ ); >+ } >+ >+ return try { >+ $item_link->delete; >+ return $c->render( >+ status => 204, >+ openapi => '' >+ ); >+ } >+ catch { >+ unless ( blessed $_ && $_->can('rethrow') ) { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check Koha logs for details." } >+ ); >+ } >+ >+ return $c->render( >+ status => 500, >+ openapi => { error => "$_" } >+ ); >+ }; >+} >+ >+1; >-- >2.24.3 (Apple Git-128)
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 24857
:
100652
|
100653
|
100654
|
100655
|
100656
|
100657
|
100658
|
100659
|
100660
|
100661
|
100662
|
101637
|
101638
|
101639
|
101640
|
101641
|
101642
|
101643
|
101644
|
101645
|
101646
|
101647
|
101648
|
101650
|
101651
|
101652
|
101653
|
101654
|
101655
|
101656
|
101657
|
101658
|
101659
|
101660
|
101661
|
101670
|
101671
|
101672
|
101673
|
101674
|
101675
|
101676
|
101677
|
101678
|
101679
|
101680
|
101681
|
101730
|
101731
|
101732
|
101733
|
101734
|
101735
|
101736
|
101737
|
101738
|
101739
|
101740
|
101741
|
101752
|
101753
|
101754
|
101755
|
101756
|
101757
|
101758
|
101759
|
101760
|
101761
|
101762
|
101763
|
104952
|
104953
|
104954
|
104955
|
104956
|
104957
|
104958
|
104959
|
104960
|
104961
|
104962
|
104963
|
104964
|
104966
|
106728
|
106729
|
106730
|
106731
|
106732
|
106733
|
106734
|
106735
|
106736
|
106737
|
106738
|
106739
|
106740
|
106741
|
108443
|
108444
|
108445
|
108446
|
108447
|
108448
|
108449
|
108450
|
108451
|
108452
|
108453
|
108454
|
108455
|
108456
|
108666
|
108667
|
108668
|
108669
|
108670
|
108671
|
108672
|
108673
|
108674
|
108675
|
108676
|
108677
|
108678
|
108679
|
108680
|
108681
|
108682
|
108683
|
108684
|
108685
|
108686
|
109074
|
109075
|
109076
|
109077
|
109078
|
109079
|
109080
|
109081
|
109082
|
109083
|
109084
|
109085
|
109086
|
109087
|
109088
|
109089
|
109090
|
109091
|
109092
|
109093
|
109094
|
109795
|
109796
|
109797
|
109798
|
109799
|
109800
|
109801
|
109802
|
109803
|
109804
|
109805
|
109806
|
109807
|
109808
|
109809
|
109810
|
109811
|
109812
|
109813
|
109814
|
109815
|
109894
|
109901
|
109902
|
109903
|
109904
|
109905
|
109906
|
109907
|
109908
|
109909
|
109910
|
109911
|
109912
|
109913
|
109914
|
109915
|
109916
|
109917
|
109918
|
109919
|
109920
|
109921
|
109922
|
109923
|
113136
|
113137
|
113138
|
113139
|
113140
|
113141
|
113142
|
113143
|
113144
|
113145
|
113146
|
113147
|
113148
|
113149
|
113150
|
113151
|
113152
|
113153
|
113154
|
113155
|
113156
|
113157
|
113158
|
113159
|
113160
|
113168
|
113169
|
113170
|
113171
|
113172
|
113173
|
113174
|
113175
|
113176
|
113177
|
113178
|
113179
|
113180
|
113181
|
113182
|
113183
|
113184
|
113185
|
113186
|
113187
|
113188
|
113189
|
113190
|
113191
|
120495
|
120496
|
120497
|
120498
|
120499
|
120500
|
120501
|
120502
|
120503
|
120504
|
120505
|
120506
|
120507
|
120508
|
120509
|
120510
|
120511
|
120512
|
120513
|
120514
|
120515
|
120516
|
120517
|
120518
|
122808
|
122809
|
122810
|
122811
|
122812
|
122813
|
122814
|
122815
|
122816
|
122817
|
122818
|
122819
|
122820
|
122821
|
122822
|
122823
|
122824
|
122825
|
122826
|
122827
|
122828
|
122829
|
122830
|
122831
|
123882
|
123883
|
123884
|
123885
|
123886
|
123887
|
123888
|
123889
|
123890
|
123891
|
123892
|
123893
|
123894
|
123895
|
123896
|
123897
|
123898
|
123899
|
123900
|
123901
|
123902
|
123903
|
123904
|
123905
|
123906
|
123907
|
123908
|
123909
|
123910
|
123912
|
124021
|
124022
|
124023
|
124024
|
124025
|
124026
|
124027
|
124028
|
124029
|
124030
|
124031
|
124032
|
124033
|
124034
|
124035
|
124036
|
124037
|
124038
|
124039
|
124040
|
124041
|
124042
|
124043
|
124044
|
124045
|
124046
|
124047
|
124048
|
124049
|
124050
|
124051
|
124052
|
124053
|
124331
|
124332
|
124333
|
124334
|
124335
|
124336
|
124337
|
124338
|
124339
|
124340
|
124341
|
124342
|
124343
|
124344
|
124345
|
124346
|
124347
|
124348
|
124349
|
124351
|
124352
|
124353
|
124354
|
124355
|
124356
|
124357
|
124358
|
124359
|
124360
|
124361
|
124362
|
124363
|
124421
|
124463
|
124583
|
124584
|
124585
|
124586
|
124587
|
124588
|
124589
|
124590
|
124591
|
124592
|
124593
|
124594
|
124595
|
124596
|
124597
|
124598
|
124599
|
124600
|
124601
|
124602
|
124603
|
124604
|
124605
|
124606
|
124607
|
124608
|
124609
|
124610
|
124611
|
124612
|
124613
|
124614
|
124615
|
131449
|
131450
|
131451
|
131452
|
131453
|
131454
|
131455
|
131456
|
134288
|
134289
|
134290
|
134291
|
134292
|
134293
|
134294
|
134295
|
134296
|
135590
|
135591
|
135592
|
135593
|
135594
|
135595
|
135596
|
135597
|
135598
|
135599
|
135600
|
135601
|
135602
|
135603
|
135604
|
135605
|
135606
|
135607
|
135608
|
135609
|
135610
|
135614
|
135615
|
135616
|
135617
|
135618
|
135619
|
135620
|
135621
|
135622
|
135623
|
135624
|
135625
|
135626
|
135627
|
135628
|
135629
|
137259
|
137260
|
137261
|
137262
|
137263
|
137264
|
137265
|
137266
|
137267
|
137268
|
137311
|
137314
|
137315
|
137316
|
137317
|
137318
|
137319
|
137320
|
137321
|
137322
|
137323
|
137441
|
137442
|
137443
|
137608
|
138933