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

(-)a/Koha/REST/V1/Biblios.pm (-12 / +8 lines)
Lines 314-337 sub add_item { Link Here
314
            $item->barcode($barcode);
314
            $item->barcode($barcode);
315
        }
315
        }
316
316
317
        if ( defined $item->barcode
317
        $item->store->discard_changes;
318
            && Koha::Items->search( { barcode => $item->barcode } )->count )
319
        {
320
            return $c->render(
321
                status  => 400,
322
                openapi => { error => "Barcode not unique" }
323
            );
324
        }
325
326
        my $storedItem = $item->store;
327
        $storedItem->discard_changes;
328
318
329
        $c->render(
319
        $c->render(
330
            status => 201,
320
            status => 201,
331
            openapi => $storedItem->to_api
321
            openapi => $item->to_api
332
        );
322
        );
333
    }
323
    }
334
    catch {
324
    catch {
325
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
326
            return $c->render(
327
                status  => 409,
328
                openapi => { error => 'Duplicate barcode.' }
329
            );
330
        }
335
        $c->unhandled_exception($_);
331
        $c->unhandled_exception($_);
336
    }
332
    }
337
}
333
}
(-)a/api/v1/swagger/paths/biblios.yaml (+4 lines)
Lines 437-442 Link Here
437
        description: Not found
437
        description: Not found
438
        schema:
438
        schema:
439
          $ref: "../swagger.yaml#/definitions/error"
439
          $ref: "../swagger.yaml#/definitions/error"
440
      "409":
441
        description: Conflict
442
        schema:
443
          $ref: "../swagger.yaml#/definitions/error"
440
      "500":
444
      "500":
441
        description: |
445
        description: |
442
          Internal server error. Possible `error_code` attribute values:
446
          Internal server error. Possible `error_code` attribute values:
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +8 lines)
Lines 1690-1696 subtest 'list() tests' => sub { Link Here
1690
};
1690
};
1691
1691
1692
subtest 'add_item() tests' => sub {
1692
subtest 'add_item() tests' => sub {
1693
  plan tests => 5;
1693
  plan tests => 7;
1694
1694
1695
  $schema->storage->txn_begin;
1695
  $schema->storage->txn_begin;
1696
1696
Lines 1735-1739 subtest 'add_item() tests' => sub { Link Here
1735
    ->status_is(201, 'Item created')
1735
    ->status_is(201, 'Item created')
1736
    ->json_is('/biblio_id', $biblio_id);
1736
    ->json_is('/biblio_id', $biblio_id);
1737
1737
1738
  my $item = $builder->build_sample_item();
1739
1740
  $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => {
1741
      external_id => $item->barcode,
1742
    })
1743
    ->status_is(409, 'Duplicate barcode');
1744
1738
  $schema->storage->txn_rollback;
1745
  $schema->storage->txn_rollback;
1739
};
1746
};
1740
- 

Return to bug 31798