From 8b5a5f46cb2da97e9a6d730b10c8729c094772f1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 14 Nov 2023 15:07:01 +0000 Subject: [PATCH] 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 --- Koha/Edifact/File.pm | 1 + Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm | 6 ++++-- api/v1/swagger/definitions/edifact_file.yaml | 5 ----- t/db_dependent/api/v1/edifact_files.t | 14 ++++++++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Koha/Edifact/File.pm b/Koha/Edifact/File.pm index 2fd475221c..66937acc27 100644 --- a/Koha/Edifact/File.pm +++ b/Koha/Edifact/File.pm @@ -68,6 +68,7 @@ sub to_api_mapping { return { message_type => 'type', basketno => 'basket_id', + deleted => undef, }; } diff --git a/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm b/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm index 1f4ae3fc09..fe9e2f3ed1 100644 --- a/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm +++ b/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm @@ -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($_); }; } diff --git a/api/v1/swagger/definitions/edifact_file.yaml b/api/v1/swagger/definitions/edifact_file.yaml index 4f32fbe4cd..2f7699de80 100644 --- a/api/v1/swagger/definitions/edifact_file.yaml +++ b/api/v1/swagger/definitions/edifact_file.yaml @@ -55,9 +55,4 @@ properties: - string - "null" description: Edifact file name - deleted: - type: - - boolean - - "null" - description: Is this file deleted additionalProperties: false diff --git a/t/db_dependent/api/v1/edifact_files.t b/t/db_dependent/api/v1/edifact_files.t index 5f85920ce8..fc0c38fa3c 100755 --- a/t/db_dependent/api/v1/edifact_files.t +++ b/t/db_dependent/api/v1/edifact_files.t @@ -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( -- 2.39.5