|
Lines 38-100
Return a list of available ILL batches
Link Here
|
| 38 |
=cut |
38 |
=cut |
| 39 |
|
39 |
|
| 40 |
sub list { |
40 |
sub list { |
| 41 |
my $c = shift->openapi->valid_input; |
41 |
my $c = shift->openapi->valid_input or return; |
| 42 |
|
|
|
| 43 |
#FIXME: This should be $c->objects-search |
| 44 |
my @batches = Koha::Illbatches->search()->as_list; |
| 45 |
|
42 |
|
| 46 |
#FIXME: Below should be coming from $c->objects accessors |
43 |
return try { |
| 47 |
# Get all patrons associated with all our batches |
44 |
my $illbatches = $c->objects->search( Koha::Illbatches->new ); |
| 48 |
# in one go |
45 |
return $c->render( status => 200, openapi => $illbatches ); |
| 49 |
my $patrons = {}; |
46 |
} catch { |
| 50 |
foreach my $batch (@batches) { |
47 |
$c->unhandled_exception($_); |
| 51 |
my $patron_id = $batch->borrowernumber; |
48 |
}; |
| 52 |
$patrons->{$patron_id} = 1; |
|
|
| 53 |
} |
| 54 |
my @patron_ids = keys %{$patrons}; |
| 55 |
my $patron_results = Koha::Patrons->search( { borrowernumber => { -in => \@patron_ids } } ); |
| 56 |
|
| 57 |
# Get all branches associated with all our batches |
| 58 |
# in one go |
| 59 |
my $branches = {}; |
| 60 |
foreach my $batch (@batches) { |
| 61 |
my $branch_id = $batch->branchcode; |
| 62 |
$branches->{$branch_id} = 1; |
| 63 |
} |
| 64 |
my @branchcodes = keys %{$branches}; |
| 65 |
my $branch_results = Koha::Libraries->search( { branchcode => { -in => \@branchcodes } } ); |
| 66 |
|
| 67 |
# Get all batch statuses associated with all our batches |
| 68 |
# in one go |
| 69 |
my $statuses = {}; |
| 70 |
foreach my $batch (@batches) { |
| 71 |
my $code = $batch->statuscode; |
| 72 |
$statuses->{$code} = 1; |
| 73 |
} |
| 74 |
my @statuscodes = keys %{$statuses}; |
| 75 |
my $status_results = Koha::IllbatchStatuses->search( { code => { -in => \@statuscodes } } ); |
| 76 |
|
| 77 |
# Populate the response |
| 78 |
my @to_return = (); |
| 79 |
foreach my $it_batch (@batches) { |
| 80 |
my $patron = $patron_results->find( { borrowernumber => $it_batch->borrowernumber } ); |
| 81 |
my $branch = $branch_results->find( { branchcode => $it_batch->branchcode } ); |
| 82 |
my $status = $status_results->find( { code => $it_batch->statuscode } ); |
| 83 |
push @to_return, { |
| 84 |
batch_id => $it_batch->id, |
| 85 |
backend => $it_batch->backend, |
| 86 |
library_id => $it_batch->branchcode, |
| 87 |
name => $it_batch->name, |
| 88 |
statuscode => $it_batch->statuscode, |
| 89 |
patron_id => $it_batch->borrowernumber, |
| 90 |
patron => $patron, |
| 91 |
branch => $branch, |
| 92 |
status => $status, |
| 93 |
requests_count => $it_batch->requests_count |
| 94 |
}; |
| 95 |
} |
| 96 |
|
49 |
|
| 97 |
return $c->render( status => 200, openapi => \@to_return ); |
|
|
| 98 |
} |
50 |
} |
| 99 |
|
51 |
|
| 100 |
=head3 get |
52 |
=head3 get |