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

(-)a/Koha/REST/V1/Biblios/ItemGroups.pm (-20 / +5 lines)
Lines 77-88 sub get { Link Here
77
            );
77
            );
78
        }
78
        }
79
        else {
79
        else {
80
            return $c->render(
80
            return $c->render_resource_not_found("Item group");
81
                status  => 404,
82
                openapi => {
83
                    error => 'Item group not found'
84
                }
85
            );
86
        }
81
        }
87
    }
82
    }
88
    catch {
83
    catch {
Lines 102-111 sub add { Link Here
102
    return try {
97
    return try {
103
98
104
        my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
99
        my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
105
        return $c->render(
100
        return $c->render_resource_not_found("Biblio")
106
            status  => 404,
101
            unless $biblio;
107
            openapi => { error => 'Object not found' }
108
        ) unless $biblio;
109
102
110
        my $item_group_data = $c->req->json;
103
        my $item_group_data = $c->req->json;
111
        # biblio_id comes from the path
104
        # biblio_id comes from the path
Lines 128-137 sub add { Link Here
128
            if (    $_->isa('Koha::Exceptions::Object::FKConstraint')
121
            if (    $_->isa('Koha::Exceptions::Object::FKConstraint')
129
                and $_->broken_fk eq 'biblio_id' )
122
                and $_->broken_fk eq 'biblio_id' )
130
            {
123
            {
131
                return $c->render(
124
                return $c->render_resource_not_found("Biblio");
132
                    status  => 404,
133
                    openapi => { error => "Biblio not found" }
134
                );
135
            }
125
            }
136
        }
126
        }
137
127
Lines 155-166 sub update { Link Here
155
        my $item_group = Koha::Biblio::ItemGroups->find( $item_group_id );
145
        my $item_group = Koha::Biblio::ItemGroups->find( $item_group_id );
156
146
157
        unless ( $item_group && $item_group->biblio_id eq $biblio_id ) {
147
        unless ( $item_group && $item_group->biblio_id eq $biblio_id ) {
158
            return $c->render(
148
            return $c->render_resource_not_found("Item group");
159
                status  => 404,
160
                openapi => {
161
                    error => 'Item group not found'
162
                }
163
            );
164
        }
149
        }
165
150
166
        my $item_group_data = $c->req->json;
151
        my $item_group_data = $c->req->json;
(-)a/Koha/REST/V1/CashRegisters/Cashups.pm (-8 / +2 lines)
Lines 42-55 sub list { Link Here
42
42
43
    my $register = Koha::Cash::Registers->find( $c->param('cash_register_id') );
43
    my $register = Koha::Cash::Registers->find( $c->param('cash_register_id') );
44
44
45
    unless ($register) {
45
    return $c->render_resource_not_found("Register")
46
        return $c->render(
46
        unless $register;
47
            status  => 404,
48
            openapi => {
49
                error => "Register not found"
50
            }
51
        );
52
    }
53
47
54
    return try {
48
    return try {
55
        my $cashups = $c->objects->search( $register->cashups );
49
        my $cashups = $c->objects->search( $register->cashups );
(-)a/Koha/REST/V1/DeletedBiblios.pm (-6 / +2 lines)
Lines 51-62 sub get { Link Here
51
51
52
    my $biblio = Koha::Old::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
52
    my $biblio = Koha::Old::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
53
53
54
    unless ($biblio) {
54
    return $c->render_resource_not_found("Biblio")
55
        return $c->render(
55
        unless $biblio;
56
            status  => 404,
57
            openapi => { error => "Object not found." }
58
        );
59
    }
60
56
61
    return try {
57
    return try {
62
58
(-)a/Koha/REST/V1/Holds.pm (-3 / +2 lines)
Lines 351-359 sub suspend { Link Here
351
351
352
    my $end_date = ($body) ? $body->{end_date} : undef;
352
    my $end_date = ($body) ? $body->{end_date} : undef;
353
353
354
    unless ($hold) {
354
    return $c->render_resource_not_found("Hold")
355
        return $c->render( status => 404, openapi => { error => 'Hold not found.' } );
355
        unless $hold;
356
    }
357
356
358
    return try {
357
    return try {
359
        $hold->suspend_hold($end_date);
358
        $hold->suspend_hold($end_date);
(-)a/Koha/REST/V1/ILL/Backends.pm (-4 / +1 lines)
Lines 96-105 sub get { Link Here
96
            openapi => $embed ? { %$return, %$embed } : $return,
96
            openapi => $embed ? { %$return, %$embed } : $return,
97
        );
97
        );
98
    } catch {
98
    } catch {
99
        return $c->render(
99
        return $c->render_resource_not_found("ILL backend");
100
            status  => 404,
101
            openapi => { error => "ILL backend does not exist" }
102
        );
103
    };
100
    };
104
}
101
}
105
102
(-)a/Koha/REST/V1/Items.pm (-6 / +2 lines)
Lines 407-418 sub remove_from_bundle { Link Here
407
    $bundle_item_id = barcodedecode($bundle_item_id);
407
    $bundle_item_id = barcodedecode($bundle_item_id);
408
    my $bundle_item = Koha::Items->find( { itemnumber => $bundle_item_id } );
408
    my $bundle_item = Koha::Items->find( { itemnumber => $bundle_item_id } );
409
409
410
    unless ($bundle_item) {
410
    return $c->render_resource_not_found("Bundle item")
411
        return $c->render(
411
        unless $bundle_item;
412
            status  => 404,
413
            openapi => { error => "Bundle item not found" }
414
        );
415
    }
416
412
417
    return try {
413
    return try {
418
        $bundle_item->remove_from_bundle;
414
        $bundle_item->remove_from_bundle;
(-)a/Koha/REST/V1/Patrons/Checkouts.pm (-6 / +2 lines)
Lines 40-51 sub list { Link Here
40
40
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
42
42
43
    unless ($patron) {
43
    return $c->render_resource_not_found("Patron")
44
        return $c->render(
44
        unless $patron;
45
            status  => 404,
46
            openapi => { error => 'Patron not found' }
47
        );
48
    }
49
45
50
    return try {
46
    return try {
51
47
(-)a/Koha/REST/V1/Patrons/Recalls.pm (-6 / +2 lines)
Lines 40-51 sub list { Link Here
40
40
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
42
42
43
    unless ($patron) {
43
    return $c->render_resource_not_found("Patron")
44
        return $c->render(
44
        unless $patron;
45
            status  => 404,
46
            openapi => { error => 'Patron not found' }
47
        );
48
    }
49
45
50
    return try {
46
    return try {
51
47
(-)a/Koha/REST/V1/Preservation/Trains.pm (-20 / +8 lines)
Lines 228-239 sub get_item { Link Here
228
        { train_item_id => $train_item_id, train_id => $train_id }
228
        { train_item_id => $train_item_id, train_id => $train_id }
229
    );
229
    );
230
230
231
    unless ($train_item) {
231
    return $c->render_resource_not_found("Item")
232
        return $c->render(
232
        unless $train_item;
233
            status  => 404,
234
            openapi => { error => "Item not found" }
235
        );
236
    }
237
233
238
    return try {
234
    return try {
239
        Koha::Database->new->schema->txn_do(
235
        Koha::Database->new->schema->txn_do(
Lines 316-325 sub add_item { Link Here
316
                    openapi => { error => "MissingSettings", parameter => $_->parameter }
312
                    openapi => { error => "MissingSettings", parameter => $_->parameter }
317
                );
313
                );
318
            } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemNotFound') ) {
314
            } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemNotFound') ) {
319
                return $c->render(
315
                return $c->render_resource_not_found("Item");
320
                    status  => 404,
321
                    openapi => { error => "Item not found" }
322
                );
323
            } elsif ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
316
            } elsif ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
324
                return $c->render(
317
                return $c->render(
325
                    status  => 409,
318
                    status  => 409,
Lines 376-387 sub copy_item { Link Here
376
            sub {
369
            sub {
377
                my $new_train_id = delete $body->{train_id};
370
                my $new_train_id = delete $body->{train_id};
378
                my $new_train    = Koha::Preservation::Trains->find($new_train_id);
371
                my $new_train    = Koha::Preservation::Trains->find($new_train_id);
379
                unless ($train) {
372
380
                    return $c->render(
373
                return $c->render_resource_not_found("Train")
381
                        status  => 404,
374
                    unless $new_train;
382
                        openapi => { error => "Train not found" }
375
383
                    );
384
                }
385
                my $new_train_item = $new_train->add_item(
376
                my $new_train_item = $new_train->add_item(
386
                    {
377
                    {
387
                        item_id       => $train_item->item_id,
378
                        item_id       => $train_item->item_id,
Lines 412-421 sub copy_item { Link Here
412
                    openapi => { error => "MissingSettings", parameter => $_->parameter }
403
                    openapi => { error => "MissingSettings", parameter => $_->parameter }
413
                );
404
                );
414
            } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemNotFound') ) {
405
            } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemNotFound') ) {
415
                return $c->render(
406
                return $c->render_resource_not_found("Item");
416
                    status  => 404,
417
                    openapi => { error => "Item not found" }
418
                );
419
            } elsif ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
407
            } elsif ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
420
                return $c->render(
408
                return $c->render(
421
                    status  => 409,
409
                    status  => 409,
(-)a/Koha/REST/V1/Static.pm (-2 / +2 lines)
Lines 55-61 sub get { Link Here
55
55
56
        @plugins = grep { $_->api_namespace eq $namespace} @plugins;
56
        @plugins = grep { $_->api_namespace eq $namespace} @plugins;
57
57
58
        return $c->render({ status => 404, openapi => { error => 'File not found' } }) unless scalar(@plugins) > 0;
58
        return $c->render_resource_not_found("File") unless scalar(@plugins) > 0;
59
        return $c->render({ status => 500, openapi => { error => 'Namespace not unique' } }) unless scalar(@plugins) == 1;
59
        return $c->render({ status => 500, openapi => { error => 'Namespace not unique' } }) unless scalar(@plugins) == 1;
60
60
61
        my $plugin = $plugins[0];
61
        my $plugin = $plugins[0];
Lines 70-76 sub get { Link Here
70
            return $c->reply->asset($asset);
70
            return $c->reply->asset($asset);
71
        }
71
        }
72
        catch {
72
        catch {
73
            return $c->render({ status => 404, openapi => { error => 'File not found' } });
73
            return $c->render_resource_not_found("File");
74
        }
74
        }
75
75
76
    } else {
76
    } else {
(-)a/Koha/REST/V1/StockRotation/Rotas.pm (-26 / +19 lines)
Lines 52-65 sub get { Link Here
52
52
53
    return try {
53
    return try {
54
        my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
54
        my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
55
        unless ($rota) {
55
56
            return $c->render(
56
        return $c->render_resource_not_found("Rota")
57
                status  => 404,
57
            unless $rota;
58
                openapi => { error => "Rota not found" }
58
59
            );
59
        return $c->render(
60
        }
60
            status  => 200,
61
61
            openapi => $c->objects->to_api($rota),
62
        return $c->render( status => 200, openapi => $rota->to_api );
62
        );
63
    } catch {
63
    } catch {
64
        $c->unhandled_exception($_);
64
        $c->unhandled_exception($_);
65
    }
65
    }
Lines 78-84 sub add { Link Here
78
        $c->res->headers->location( $c->req->url->to_string . '/' . $rota->rota_id );
78
        $c->res->headers->location( $c->req->url->to_string . '/' . $rota->rota_id );
79
        return $c->render(
79
        return $c->render(
80
            status  => 201,
80
            status  => 201,
81
            openapi => $rota->to_api
81
            openapi => $c->objects->to_api($rota),
82
        );
82
        );
83
    } catch {
83
    } catch {
84
        $c->unhandled_exception($_);
84
        $c->unhandled_exception($_);
Lines 94-110 sub update { Link Here
94
94
95
    my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
95
    my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
96
96
97
    if ( not defined $rota ) {
97
    return $c->render_resource_not_found("Rota")
98
        return $c->render(
98
        unless $rota;
99
            status  => 404,
100
            openapi => { error => "Object not found" }
101
        );
102
    }
103
99
104
    return try {
100
    return try {
105
        $rota->set_from_api( $c->req->json );
101
        $rota->set_from_api( $c->req->json );
106
        $rota->store();
102
        $rota->store();
107
        return $c->render( status => 200, openapi => $rota->to_api );
103
        return $c->render(
104
            status  => 200,
105
            openapi => $c->objects->to_api($rota),
106
        );
108
    } catch {
107
    } catch {
109
        $c->unhandled_exception($_);
108
        $c->unhandled_exception($_);
110
    };
109
    };
Lines 118-136 sub delete { Link Here
118
    my $c = shift->openapi->valid_input or return;
117
    my $c = shift->openapi->valid_input or return;
119
118
120
    my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
119
    my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
121
    if ( not defined $rota ) {
120
122
        return $c->render(
121
    return $c->render_resource_not_found("Rota")
123
            status  => 404,
122
        unless $rota;
124
            openapi => { error => "Object not found" }
125
        );
126
    }
127
123
128
    return try {
124
    return try {
129
        $rota->delete;
125
        $rota->delete;
130
        return $c->render(
126
        return $c->render_resource_deleted;
131
            status  => 204,
132
            openapi => q{}
133
        );
134
    } catch {
127
    } catch {
135
        $c->unhandled_exception($_);
128
        $c->unhandled_exception($_);
136
    };
129
    };
(-)a/Koha/REST/V1/StockRotation/Stage.pm (-5 / +4 lines)
Lines 48-58 sub move { Link Here
48
            status  => 400
48
            status  => 400
49
        );
49
        );
50
    }
50
    }
51
    else {
51
    elsif ($rota) {
52
        return $c->render(
52
        return $c->render_resource_not_found("Stage");
53
            openapi => { error => "Not found - Invalid rota or stage ID" },
53
    } else {
54
            status  => 404
54
        return $c->render_resource_not_found("Rota");
55
        );
56
    }
55
    }
57
}
56
}
58
57
(-)a/Koha/REST/V1/TransferLimits.pm (-3 / +2 lines)
Lines 103-111 sub delete { Link Here
103
103
104
    my $transfer_limit = Koha::Item::Transfer::Limits->find( $c->param( 'limit_id' ) );
104
    my $transfer_limit = Koha::Item::Transfer::Limits->find( $c->param( 'limit_id' ) );
105
105
106
    if ( not defined $transfer_limit ) {
106
    return $c->render_resource_not_found("Transfer limit")
107
        return $c->render( status => 404, openapi => { error => "Transfer limit not found" } );
107
        unless $transfer_limit;
108
    }
109
108
110
    return try {
109
    return try {
111
        $transfer_limit->delete;
110
        $transfer_limit->delete;
(-)a/t/db_dependent/api/v1/deleted_biblios.t (-1 / +1 lines)
Lines 103-109 subtest 'get() tests' => sub { Link Here
103
    my $biblio_exist = $builder->build_sample_biblio();
103
    my $biblio_exist = $builder->build_sample_biblio();
104
    $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/"
104
    $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/"
105
            . $biblio_exist->biblionumber => { Accept => 'application/marc' } )->status_is(404)
105
            . $biblio_exist->biblionumber => { Accept => 'application/marc' } )->status_is(404)
106
        ->json_is( '/error', 'Object not found.' );
106
        ->json_is( '/error', 'Biblio not found' );
107
107
108
    subtest 'marc-in-json encoding tests' => sub {
108
    subtest 'marc-in-json encoding tests' => sub {
109
109
(-)a/t/db_dependent/api/v1/preservation_Trains.t (-1 / +1 lines)
Lines 458-464 subtest '*_item() tests' => sub { Link Here
458
    $item_2->delete;
458
    $item_2->delete;
459
    $t->post_ok(
459
    $t->post_ok(
460
        "//$userid:$password@/api/v1/preservation/trains/$train_id/items" => json => { item_id => $item_2->itemnumber }
460
        "//$userid:$password@/api/v1/preservation/trains/$train_id/items" => json => { item_id => $item_2->itemnumber }
461
    )->status_is(404)->json_is( { error => 'Item not found' } );
461
    )->status_is(404)->json_is( { error => 'Item not found', error_code => 'not_found' } );
462
462
463
    # batch add items
463
    # batch add items
464
    # Nothing added (FIXME maybe not 201?)
464
    # Nothing added (FIXME maybe not 201?)
(-)a/t/db_dependent/api/v1/stockrotationstage.t (-3 / +2 lines)
Lines 82-94 subtest 'move() tests' => sub { Link Here
82
    $t->put_ok( "//$auth_userid:$password@/api/v1/rotas/99999999/stages/$stage1_id/position"
82
    $t->put_ok( "//$auth_userid:$password@/api/v1/rotas/99999999/stages/$stage1_id/position"
83
          => json => 2 )
83
          => json => 2 )
84
      ->status_is(404)
84
      ->status_is(404)
85
      ->json_is( '/error' => "Not found - Invalid rota or stage ID" );
85
      ->json_is( '/error' => "Rota not found" );
86
86
87
    # Invalid attempt to move an non-existant stage
87
    # Invalid attempt to move an non-existant stage
88
    $t->put_ok( "//$auth_userid:$password@/api/v1/rotas/$rota_id/stages/999999999/position"
88
    $t->put_ok( "//$auth_userid:$password@/api/v1/rotas/$rota_id/stages/999999999/position"
89
          => json => 2 )
89
          => json => 2 )
90
      ->status_is(404)
90
      ->status_is(404)
91
      ->json_is( '/error' => "Not found - Invalid rota or stage ID" );
91
      ->json_is( '/error' => "Stage not found" );
92
92
93
    # Invalid attempt to move stage to current position
93
    # Invalid attempt to move stage to current position
94
    my $curr_position = $stage1->{position};
94
    my $curr_position = $stage1->{position};
95
- 

Return to bug 37686