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

(-)a/Koha/REST/V1/Biblios.pm (-12 / +8 lines)
Lines 310-333 sub add_item { Link Here
310
            $item->barcode($barcode);
310
            $item->barcode($barcode);
311
        }
311
        }
312
312
313
        if ( defined $item->barcode
313
        $item->store->discard_changes;
314
            && Koha::Items->search( { barcode => $item->barcode } )->count )
315
        {
316
            return $c->render(
317
                status  => 400,
318
                openapi => { error => "Barcode not unique" }
319
            );
320
        }
321
322
        my $storedItem = $item->store;
323
        $storedItem->discard_changes;
324
314
325
        $c->render(
315
        $c->render(
326
            status => 201,
316
            status => 201,
327
            openapi => $storedItem->to_api
317
            openapi => $item->to_api
328
        );
318
        );
329
    }
319
    }
330
    catch {
320
    catch {
321
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
322
            return $c->render(
323
                status  => 409,
324
                openapi => { error => 'Duplicate barcode.' }
325
            );
326
        }
331
        $c->unhandled_exception($_);
327
        $c->unhandled_exception($_);
332
    }
328
    }
333
}
329
}
(-)a/api/v1/swagger/paths/biblios.yaml (+4 lines)
Lines 254-259 Link Here
254
        description: Not found
254
        description: Not found
255
        schema:
255
        schema:
256
          $ref: "../swagger.yaml#/definitions/error"
256
          $ref: "../swagger.yaml#/definitions/error"
257
      "409":
258
        description: Conflict
259
        schema:
260
          $ref: "../swagger.yaml#/definitions/error"
257
      "500":
261
      "500":
258
        description: |
262
        description: |
259
          Internal server error. Possible `error_code` attribute values:
263
          Internal server error. Possible `error_code` attribute values:
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +8 lines)
Lines 715-721 subtest 'set_rating() tests' => sub { Link Here
715
};
715
};
716
716
717
subtest 'add_item() tests' => sub {
717
subtest 'add_item() tests' => sub {
718
  plan tests => 5;
718
  plan tests => 7;
719
719
720
  $schema->storage->txn_begin;
720
  $schema->storage->txn_begin;
721
721
Lines 760-764 subtest 'add_item() tests' => sub { Link Here
760
    ->status_is(201, 'Item created')
760
    ->status_is(201, 'Item created')
761
    ->json_is('/biblio_id', $biblio_id);
761
    ->json_is('/biblio_id', $biblio_id);
762
762
763
  my $item = $builder->build_sample_item();
764
765
  $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => {
766
      external_id => $item->barcode,
767
    })
768
    ->status_is(409, 'Duplicate barcode');
769
763
  $schema->storage->txn_rollback;
770
  $schema->storage->txn_rollback;
764
};
771
};
765
- 

Return to bug 31798