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

(-)a/Koha/REST/V1/RecordSources.pm (-1 / +11 lines)
Lines 23-29 use Mojo::Base 'Mojolicious::Controller'; Link Here
23
23
24
use Koha::RecordSources;
24
use Koha::RecordSources;
25
25
26
use Try::Tiny qw( catch try );
26
use Scalar::Util qw( blessed );
27
use Try::Tiny    qw( catch try );
27
28
28
=head1 API
29
=head1 API
29
30
Lines 121-126 sub delete { Link Here
121
        $source->delete;
122
        $source->delete;
122
        return $c->render_resource_deleted;
123
        return $c->render_resource_deleted;
123
    } catch {
124
    } catch {
125
        if ( blessed($_) && ref($_) eq 'Koha::Exceptions::Object::FKConstraintDeletion' ) {
126
            return $c->render(
127
                status  => 409,
128
                openapi => {
129
                    error      => 'Cannot delete record source linked to existing records',
130
                    error_code => 'cannot_delete_used',
131
                }
132
            );
133
        }
124
        $c->unhandled_exception($_);
134
        $c->unhandled_exception($_);
125
    };
135
    };
126
}
136
}
(-)a/api/v1/swagger/paths/record_sources.yaml (+7 lines)
Lines 233-238 Link Here
233
        description: Not found
233
        description: Not found
234
        schema:
234
        schema:
235
          $ref: "../swagger.yaml#/definitions/error"
235
          $ref: "../swagger.yaml#/definitions/error"
236
      "409":
237
        description: |
238
          Conflict in deleting resource. Possible `error_code` attribute values:
239
240
          * `cannot_delete_used`: record source linked to a record cannot be deleted.
241
        schema:
242
          $ref: "../swagger.yaml#/definitions/error"
236
      "500":
243
      "500":
237
        description: |
244
        description: |
238
          Internal server error. Possible `error_code` attribute values:
245
          Internal server error. Possible `error_code` attribute values:
(-)a/t/db_dependent/api/v1/record_sources.t (-2 / +9 lines)
Lines 136-142 subtest 'get() tests' => sub { Link Here
136
136
137
subtest 'delete() tests' => sub {
137
subtest 'delete() tests' => sub {
138
138
139
    plan tests => 10;
139
    plan tests => 12;
140
140
141
    $schema->storage->txn_begin;
141
    $schema->storage->txn_begin;
142
142
Lines 175-180 subtest 'delete() tests' => sub { Link Here
175
    $source = $builder->build_object( { class => 'Koha::RecordSources' } );
175
    $source = $builder->build_object( { class => 'Koha::RecordSources' } );
176
    $id     = $source->id;
176
    $id     = $source->id;
177
177
178
    my $biblio   = $builder->build_sample_biblio();
179
    my $metadata = $biblio->metadata;
180
    $metadata->record_source_id( $source->id )->store();
181
182
    $t->delete_ok("//$userid:$password@/api/v1/record_sources/$id")->status_is( 409, 'REST3.2.4.1' );
183
184
    $biblio->delete();
185
178
    $t->delete_ok("//$userid:$password@/api/v1/record_sources/$id")->status_is( 204, 'REST3.2.4' )
186
    $t->delete_ok("//$userid:$password@/api/v1/record_sources/$id")->status_is( 204, 'REST3.2.4' )
179
        ->content_is( q{}, 'REST3.3.4' );
187
        ->content_is( q{}, 'REST3.3.4' );
180
188
181
- 

Return to bug 37513