Lines 21-26
use Modern::Perl;
Link Here
|
21 |
use Mojolicious::Lite; |
21 |
use Mojolicious::Lite; |
22 |
use Try::Tiny; |
22 |
use Try::Tiny; |
23 |
|
23 |
|
|
|
24 |
use Koha::Cities; |
25 |
|
24 |
app->log->level('error'); |
26 |
app->log->level('error'); |
25 |
|
27 |
|
26 |
plugin 'Koha::REST::Plugin::Query'; |
28 |
plugin 'Koha::REST::Plugin::Query'; |
Lines 92-105
get '/dbic_merge_sorting_single' => sub {
Link Here
|
92 |
$c->render( json => $attributes, status => 200 ); |
94 |
$c->render( json => $attributes, status => 200 ); |
93 |
}; |
95 |
}; |
94 |
|
96 |
|
95 |
get '/dbic_merge_sorting_to_model' => sub { |
97 |
get '/dbic_merge_sorting_result_set' => sub { |
96 |
my $c = shift; |
98 |
my $c = shift; |
97 |
my $attributes = { a => 'a', b => 'b' }; |
99 |
my $attributes = { a => 'a', b => 'b' }; |
|
|
100 |
my $result_set = Koha::Cities->new; |
98 |
$attributes = $c->dbic_merge_sorting( |
101 |
$attributes = $c->dbic_merge_sorting( |
99 |
{ |
102 |
{ |
100 |
attributes => $attributes, |
103 |
attributes => $attributes, |
101 |
params => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] }, |
104 |
params => { _match => 'exact', _order_by => [ 'name', '-postal_code', '+country', ' state' ] }, |
102 |
to_model => \&to_model |
105 |
result_set => $result_set |
103 |
} |
106 |
} |
104 |
); |
107 |
); |
105 |
$c->render( json => $attributes, status => 200 ); |
108 |
$c->render( json => $attributes, status => 200 ); |
Lines 122-134
get '/build_query' => sub {
Link Here
|
122 |
}; |
125 |
}; |
123 |
}; |
126 |
}; |
124 |
|
127 |
|
125 |
sub to_model { |
|
|
126 |
my ($args) = @_; |
127 |
$args->{three} = delete $args->{tres} |
128 |
if exists $args->{tres}; |
129 |
return $args; |
130 |
} |
131 |
|
132 |
# The tests |
128 |
# The tests |
133 |
|
129 |
|
134 |
use Test::More tests => 3; |
130 |
use Test::More tests => 3; |
Lines 178-191
subtest 'dbic_merge_sorting() tests' => sub {
Link Here
|
178 |
] |
174 |
] |
179 |
); |
175 |
); |
180 |
|
176 |
|
181 |
$t->get_ok('/dbic_merge_sorting_to_model')->status_is(200) |
177 |
$t->get_ok('/dbic_merge_sorting_result_set')->status_is(200) |
182 |
->json_is( '/a' => 'a', 'Existing values are kept (a)' ) |
178 |
->json_is( '/a' => 'a', 'Existing values are kept (a)' ) |
183 |
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( |
179 |
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( |
184 |
'/order_by' => [ |
180 |
'/order_by' => [ |
185 |
'uno', |
181 |
'city_name', |
186 |
{ -desc => 'dos' }, |
182 |
{ -desc => 'city_zipcode' }, |
187 |
{ -asc => 'three' }, |
183 |
{ -asc => 'city_country' }, |
188 |
{ -asc => 'cuatro' } |
184 |
{ -asc => 'city_state' } |
189 |
] |
185 |
] |
190 |
); |
186 |
); |
191 |
|
187 |
|
192 |
- |
|
|