View | Details | Raw Unified | Return to bug 19370
Collapse All | Expand All

(-)a/Koha/REST/Plugin/Query.pm (-3 / +4 lines)
Lines 83-89 Generates the DBIC order_by attributes based on I<$params>, and merges into I<$a Link Here
83
83
84
            if ( defined $args->{params}->{_order_by} ) {
84
            if ( defined $args->{params}->{_order_by} ) {
85
                my @order_by = map { _build_order_atom($_) }
85
                my @order_by = map { _build_order_atom($_) }
86
                                split( /\|/, $args->{params}->{_order_by} );
86
                               @{ $args->{params}->{_order_by} };
87
                $attributes->{order_by} = \@order_by;
87
                $attributes->{order_by} = \@order_by;
88
            }
88
            }
89
89
Lines 167-175 according to the following rules: Link Here
167
sub _build_order_atom {
167
sub _build_order_atom {
168
    my $string = shift;
168
    my $string = shift;
169
169
170
    if ( $string =~ m/^\+/ ) {
170
    if ( $string =~ m/^\+/ or
171
         $string =~ m/^\s/ ) {
171
        # asc order operator present
172
        # asc order operator present
172
        $string =~ s/^\+//;
173
        $string =~ s/^(\+|\s)//;
173
        return { -asc => $string };
174
        return { -asc => $string };
174
    }
175
    }
175
    elsif ( $string =~ m/^\-/ ) {
176
    elsif ( $string =~ m/^\-/ ) {
(-)a/t/Koha/REST/Plugin/Query.t (-6 / +11 lines)
Lines 74-80 get '/dbic_merge_sorting' => sub { Link Here
74
    $attributes = $c->dbic_merge_sorting(
74
    $attributes = $c->dbic_merge_sorting(
75
        {
75
        {
76
            attributes => $attributes,
76
            attributes => $attributes,
77
            params     => { _match => 'exact', _order_by => 'uno|-dos|+tres' }
77
            params     => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] }
78
        }
78
        }
79
    );
79
    );
80
    $c->render( json => $attributes, status => 200 );
80
    $c->render( json => $attributes, status => 200 );
Lines 135-147 subtest 'dbic_merge_sorting() tests' => sub { Link Here
135
135
136
    my $t = Test::Mojo->new;
136
    my $t = Test::Mojo->new;
137
137
138
    $t->get_ok('/dbic_merge_sorting')
138
    $t->get_ok('/dbic_merge_sorting')->status_is(200)
139
      ->status_is(200)
140
      ->json_is( '/a' => 'a', 'Existing values are kept (a)' )
139
      ->json_is( '/a' => 'a', 'Existing values are kept (a)' )
141
      ->json_is( '/b' => 'b', 'Existing values are kept (b)' )
140
      ->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is(
142
      ->json_is( '/order_by' => [ 'uno', { -desc => 'dos' }, { -asc => 'tres' } ] );
141
        '/order_by' => [
142
            'uno',
143
            { -desc => 'dos' },
144
            { -asc  => 'tres' },
145
            { -asc  => 'cuatro' }
146
        ]
147
      );
143
};
148
};
144
149
150
145
subtest '_build_query_params_from_api' => sub {
151
subtest '_build_query_params_from_api' => sub {
146
152
147
    plan tests => 16;
153
    plan tests => 16;
148
- 

Return to bug 19370