Lines 56-89
Get one batch
Link Here
|
56 |
=cut |
56 |
=cut |
57 |
|
57 |
|
58 |
sub get { |
58 |
sub get { |
59 |
my $c = shift->openapi->valid_input; |
59 |
my $c = shift->openapi->valid_input or return; |
60 |
|
60 |
|
61 |
my $batchid = $c->param('ill_batch_id'); |
61 |
return try { |
|
|
62 |
my $ill_batch = $c->objects->find( Koha::Illbatches->search, $c->param('ill_batch_id') ); |
62 |
|
63 |
|
63 |
my $batch = Koha::Illbatches->find($batchid); |
64 |
unless ($ill_batch) { |
|
|
65 |
return $c->render( |
66 |
status => 404, |
67 |
openapi => { error => "ILL batch not found" } |
68 |
); |
69 |
} |
64 |
|
70 |
|
65 |
if ( not defined $batch ) { |
|
|
66 |
return $c->render( |
71 |
return $c->render( |
67 |
status => 404, |
72 |
status => 200, |
68 |
openapi => { error => "ILL batch not found" } |
73 |
openapi => $ill_batch |
69 |
); |
74 |
); |
70 |
} |
75 |
} catch { |
71 |
|
76 |
$c->unhandled_exception($_); |
72 |
return $c->render( |
77 |
}; |
73 |
status => 200, |
|
|
74 |
openapi => { |
75 |
batch_id => $batch->id, |
76 |
backend => $batch->backend, |
77 |
library_id => $batch->branchcode, |
78 |
name => $batch->name, |
79 |
statuscode => $batch->statuscode, |
80 |
patron_id => $batch->borrowernumber, |
81 |
patron => $batch->patron->unblessed, |
82 |
branch => $batch->branch->unblessed, |
83 |
status => $batch->status->unblessed, |
84 |
requests_count => $batch->requests_count |
85 |
} |
86 |
); |
87 |
} |
78 |
} |
88 |
|
79 |
|
89 |
=head3 add |
80 |
=head3 add |
Lines 97-104
sub add {
Link Here
|
97 |
|
88 |
|
98 |
my $body = $c->req->json; |
89 |
my $body = $c->req->json; |
99 |
|
90 |
|
100 |
# We receive cardnumber, so we need to look up the corresponding |
|
|
101 |
# borrowernumber |
102 |
my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } ); |
91 |
my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } ); |
103 |
|
92 |
|
104 |
if ( not defined $patron ) { |
93 |
if ( not defined $patron ) { |
Lines 113-138
sub add {
Link Here
|
113 |
$body->{branchcode} = delete $body->{library_id}; |
102 |
$body->{branchcode} = delete $body->{library_id}; |
114 |
|
103 |
|
115 |
return try { |
104 |
return try { |
116 |
my $batch = Koha::Illbatch->new($body); |
105 |
my $batch = Koha::Illbatch->new_from_api($body); |
117 |
$batch->create_and_log; |
106 |
$batch->create_and_log; |
|
|
107 |
|
118 |
$c->res->headers->location( $c->req->url->to_string . '/' . $batch->id ); |
108 |
$c->res->headers->location( $c->req->url->to_string . '/' . $batch->id ); |
119 |
|
109 |
|
120 |
my $ret = { |
110 |
my $ill_batch = $c->objects->find( Koha::Illbatches->search, $batch->id ); |
121 |
batch_id => $batch->id, |
|
|
122 |
backend => $batch->backend, |
123 |
library_id => $batch->branchcode, |
124 |
name => $batch->name, |
125 |
statuscode => $batch->statuscode, |
126 |
patron_id => $batch->borrowernumber, |
127 |
patron => $batch->patron->unblessed, |
128 |
branch => $batch->branch->unblessed, |
129 |
status => $batch->status->unblessed, |
130 |
requests_count => 0 |
131 |
}; |
132 |
|
111 |
|
133 |
return $c->render( |
112 |
return $c->render( |
134 |
status => 201, |
113 |
status => 201, |
135 |
openapi => $ret |
114 |
openapi => $ill_batch |
136 |
); |
115 |
); |
137 |
} catch { |
116 |
} catch { |
138 |
if ( blessed $_ ) { |
117 |
if ( blessed $_ ) { |
Lines 158-164
sub update {
Link Here
|
158 |
|
137 |
|
159 |
my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') ); |
138 |
my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') ); |
160 |
|
139 |
|
161 |
if ( not defined $batch ) { |
140 |
unless ($batch) { |
162 |
return $c->render( |
141 |
return $c->render( |
163 |
status => 404, |
142 |
status => 404, |
164 |
openapi => { error => "ILL batch not found" } |
143 |
openapi => { error => "ILL batch not found" } |
Lines 173-194
sub update {
Link Here
|
173 |
return try { |
152 |
return try { |
174 |
$batch->update_and_log($params); |
153 |
$batch->update_and_log($params); |
175 |
|
154 |
|
176 |
my $ret = { |
|
|
177 |
batch_id => $batch->id, |
178 |
backend => $batch->backend, |
179 |
library_id => $batch->branchcode, |
180 |
name => $batch->name, |
181 |
statuscode => $batch->statuscode, |
182 |
patron_id => $batch->borrowernumber, |
183 |
patron => $batch->patron->unblessed, |
184 |
branch => $batch->branch->unblessed, |
185 |
status => $batch->status->unblessed, |
186 |
requests_count => $batch->requests_count |
187 |
}; |
188 |
|
189 |
return $c->render( |
155 |
return $c->render( |
190 |
status => 200, |
156 |
status => 200, |
191 |
openapi => $ret |
157 |
openapi => $batch->to_api |
192 |
); |
158 |
); |
193 |
} catch { |
159 |
} catch { |
194 |
$c->unhandled_exception($_); |
160 |
$c->unhandled_exception($_); |