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

(-)a/Koha/REST/Plugin/Query.pm (-3 / +4 lines)
Lines 81-87 Generates the DBIC order_by attributes based on I<$params>, and merges into I<$a Link Here
81
81
82
            if ( defined $args->{params}->{_order_by} ) {
82
            if ( defined $args->{params}->{_order_by} ) {
83
                my @order_by = map { _build_order_atom($_) }
83
                my @order_by = map { _build_order_atom($_) }
84
                                split( /\|/, $args->{params}->{_order_by} );
84
                               @{ $args->{params}->{_order_by} };
85
                $attributes->{order_by} = \@order_by;
85
                $attributes->{order_by} = \@order_by;
86
            }
86
            }
87
87
Lines 120-128 according to the following rules: Link Here
120
sub _build_order_atom {
120
sub _build_order_atom {
121
    my $string = shift;
121
    my $string = shift;
122
122
123
    if ( $string =~ m/^\+/ ) {
123
    if ( $string =~ m/^\+/ or
124
         $string =~ m/^\s/ ) {
124
        # asc order operator present
125
        # asc order operator present
125
        $string =~ s/^\+//;
126
        $string =~ s/^(\+|\s)//;
126
        return { -asc => $string };
127
        return { -asc => $string };
127
    }
128
    }
128
    elsif ( $string =~ m/^\-/ ) {
129
    elsif ( $string =~ m/^\-/ ) {
(-)a/t/Koha/REST/Plugin/Query.t (-6 / +10 lines)
Lines 73-79 get '/dbic_merge_sorting' => sub { Link Here
73
    $attributes = $c->dbic_merge_sorting(
73
    $attributes = $c->dbic_merge_sorting(
74
        {
74
        {
75
            attributes => $attributes,
75
            attributes => $attributes,
76
            params     => { _match => 'exact', _order_by => 'uno|-dos|+tres' }
76
            params     => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] }
77
        }
77
        }
78
    );
78
    );
79
    $c->render( json => $attributes, status => 200 );
79
    $c->render( json => $attributes, status => 200 );
Lines 117-125 subtest 'dbic_merge_sorting() tests' => sub { Link Here
117
117
118
    my $t = Test::Mojo->new;
118
    my $t = Test::Mojo->new;
119
119
120
    $t->get_ok('/dbic_merge_sorting')
120
    $t->get_ok('/dbic_merge_sorting')->status_is(200)
121
      ->status_is(200)
122
      ->json_is( '/a' => 'a', 'Existing values are kept (a)' )
121
      ->json_is( '/a' => 'a', 'Existing values are kept (a)' )
123
      ->json_is( '/b' => 'b', 'Existing values are kept (b)' )
122
      ->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is(
124
      ->json_is( '/order_by' => [ 'uno', { -desc => 'dos' }, { -asc => 'tres' } ] );
123
        '/order_by' => [
124
            'uno',
125
            { -desc => 'dos' },
126
            { -asc  => 'tres' },
127
            { -asc  => 'cuatro' }
128
        ]
129
      );
125
};
130
};
126
- 

Return to bug 19370