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

(-)a/Koha/REST/V1/DeletedItems.pm (-1 / +12 lines)
Lines 19-27 use Modern::Perl; Link Here
19
19
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Exceptions;
22
use Koha::Old::Items;
23
use Koha::Old::Items;
23
24
24
use Try::Tiny qw( catch try );
25
use Scalar::Util qw( blessed );
26
use Try::Tiny    qw( catch try );
25
27
26
=head1 API
28
=head1 API
27
29
Lines 90-95 sub restore { Link Here
90
            openapi => $c->objects->to_api($item),
92
            openapi => $c->objects->to_api($item),
91
        );
93
        );
92
    } catch {
94
    } catch {
95
        if ( blessed $_ && $_->isa('Koha::Exceptions::ObjectNotFound') ) {
96
            return $c->render(
97
                status  => 409,
98
                openapi => {
99
                    error =>
100
                        "Bibliographic record not found for this item. Cannot restore item without its bibliographic record."
101
                }
102
            );
103
        }
93
        $c->unhandled_exception($_);
104
        $c->unhandled_exception($_);
94
    };
105
    };
95
}
106
}
(-)a/api/v1/swagger/paths/deleted_items.yaml (+4 lines)
Lines 129-134 Link Here
129
        description: Deleted item not found
129
        description: Deleted item not found
130
        schema:
130
        schema:
131
          $ref: "../swagger.yaml#/definitions/error"
131
          $ref: "../swagger.yaml#/definitions/error"
132
      "409":
133
        description: Cannot restore item - bibliographic record not found
134
        schema:
135
          $ref: "../swagger.yaml#/definitions/error"
132
      "500":
136
      "500":
133
        description: |
137
        description: |
134
          Internal server error. Possible `error_code` attribute values:
138
          Internal server error. Possible `error_code` attribute values:
(-)a/t/db_dependent/api/v1/deleted_items.t (-2 / +12 lines)
Lines 127-133 subtest 'get() tests' => sub { Link Here
127
127
128
subtest 'restore() tests' => sub {
128
subtest 'restore() tests' => sub {
129
129
130
    plan tests => 11;
130
    plan tests => 15;
131
131
132
    $schema->storage->txn_begin;
132
    $schema->storage->txn_begin;
133
133
Lines 183-187 subtest 'restore() tests' => sub { Link Here
183
183
184
    $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404);
184
    $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404);
185
185
186
    my $item_without_biblio = $builder->build_sample_item( { barcode => 'TEST_NO_BIBLIO' } );
187
    my $orphan_item_id      = $item_without_biblio->itemnumber;
188
    my $orphan_biblio_id    = $item_without_biblio->biblionumber;
189
    my $orphan_item_data    = $item_without_biblio->unblessed;
190
    my $deleted_orphan_item = Koha::Old::Item->new($orphan_item_data)->store;
191
    $item_without_biblio->delete;
192
    Koha::Biblios->find($orphan_biblio_id)->delete;
193
194
    $t->put_ok("//$userid:$password@/api/v1/deleted/items/$orphan_item_id")->status_is(409)->json_has('/error')
195
        ->json_like( '/error', qr/Bibliographic record not found/ );
196
186
    $schema->storage->txn_rollback;
197
    $schema->storage->txn_rollback;
187
};
198
};
188
- 

Return to bug 17387