Lines 44-105
sub list {
Link Here
|
44 |
|
44 |
|
45 |
return try { |
45 |
return try { |
46 |
|
46 |
|
47 |
my $patrons_rs = Koha::Patrons->new; |
47 |
my $query = {}; |
48 |
my $args = $c->validation->output; |
48 |
my $restricted = delete $c->validation->output->{restricted}; |
49 |
my $attributes = {}; |
49 |
$query->{debarred} = { '!=' => undef } |
|
|
50 |
if $restricted; |
50 |
|
51 |
|
51 |
# Extract reserved params |
52 |
my $patrons_rs = Koha::Patrons->search($query); |
52 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args); |
53 |
my $patrons = $c->objects->search( $patrons_rs ); |
53 |
|
54 |
|
54 |
my $restricted = delete $filtered_params->{restricted}; |
55 |
return $c->render( |
55 |
|
56 |
status => 200, |
56 |
# Merge sorting into query attributes |
57 |
openapi => $patrons |
57 |
$c->dbic_merge_sorting( |
|
|
58 |
{ |
59 |
attributes => $attributes, |
60 |
params => $reserved_params, |
61 |
result_set => $patrons_rs |
62 |
} |
63 |
); |
64 |
|
65 |
# Merge pagination into query attributes |
66 |
$c->dbic_merge_pagination( |
67 |
{ |
68 |
filter => $attributes, |
69 |
params => $reserved_params |
70 |
} |
71 |
); |
72 |
|
73 |
if ( defined $filtered_params ) { |
74 |
|
75 |
# Apply the mapping function to the passed params |
76 |
$filtered_params = $patrons_rs->attributes_from_api($filtered_params); |
77 |
$filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); |
78 |
} |
79 |
|
80 |
# translate 'restricted' => 'debarred' |
81 |
$filtered_params->{debarred} = { '!=' => undef } |
82 |
if $restricted; |
83 |
|
84 |
my $patrons = $patrons_rs->search( $filtered_params, $attributes ); |
85 |
my $total = $patrons_rs->search->count; |
86 |
|
87 |
$c->add_pagination_headers( |
88 |
{ |
89 |
total => ($patrons->is_paged ? $patrons->pager->total_entries : $patrons->count), |
90 |
base_total => $total, |
91 |
params => $args, |
92 |
} |
93 |
); |
58 |
); |
94 |
|
|
|
95 |
return $c->render( status => 200, openapi => $patrons->to_api ); |
96 |
} |
59 |
} |
97 |
catch { |
60 |
catch { |
98 |
$c->unhandled_exception($_); |
61 |
$c->unhandled_exception($_); |
99 |
}; |
62 |
}; |
100 |
} |
63 |
} |
101 |
|
64 |
|
102 |
|
|
|
103 |
=head3 get |
65 |
=head3 get |
104 |
|
66 |
|
105 |
Controller function that handles retrieving a single Koha::Patron object |
67 |
Controller function that handles retrieving a single Koha::Patron object |
106 |
- |
|
|