Bug 30070: (follow-up) Filter out deleted files on the API

EDI uses a 'deleted' flag in the table to denote deleted files, we
should filter those out of the API response.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2023-11-14 15:07:01 +00:00 committed by Katrin Fischer
parent a2fb53a719
commit 8b5a5f46cb
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
4 changed files with 15 additions and 11 deletions

View File

@ -68,6 +68,7 @@ sub to_api_mapping {
return {
message_type => 'type',
basketno => 'basket_id',
deleted => undef,
};
}

View File

@ -46,16 +46,18 @@ Return the list of edifact files
sub list {
my $c = shift->openapi->valid_input or return;
my $filter = { deleted => 0 };
return try {
my $files_rs = Koha::Edifact::Files->new;
my $files_rs = Koha::Edifact::Files->search($filter);
my $files = $c->objects->search($files_rs);
return $c->render(
status => 200,
openapi => $files,
);
} catch {
}
catch {
$c->unhandled_exception($_);
};
}

View File

@ -55,9 +55,4 @@ properties:
- string
- "null"
description: Edifact file name
deleted:
type:
- boolean
- "null"
description: Is this file deleted
additionalProperties: false

View File

@ -66,15 +66,21 @@ subtest 'list() tests' => sub {
# No acquisitions\/edifiles, so empty array should be returned
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( [] );
my $file = $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'ORDER' } } );
my $file = $builder->build_object(
{ class => 'Koha::Edifact::Files', value => { message_type => 'ORDER', deleted => 0 } } );
# One file created, should get returned
my $deleted_file = $builder->build_object(
{ class => 'Koha::Edifact::Files', value => { message_type => 'ORDER', deleted => 1 } } );
# One file undeleted, should get returned
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( [ $file->to_api ] );
my $another_file_ORDER =
$builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'ORDER' } } );
$builder->build_object(
{ class => 'Koha::Edifact::Files', value => { message_type => 'ORDER', deleted => 0 } } );
my $another_file_QUOTE =
$builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'QUOTE' } } );
$builder->build_object(
{ class => 'Koha::Edifact::Files', value => { message_type => 'QUOTE', deleted => 0 } } );
# Two files created, they should both be returned
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is(