From b96b6e8f4c4592f511df27f82eb169822b28c65e Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 19 Dec 2024 17:16:47 +0000
Subject: [PATCH] Bug 38689: Add Koha::Edifact::File::Error(s) classes

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 Koha/Edifact/File.pm                          | 16 ++++
 Koha/Edifact/File/Error.pm                    | 78 +++++++++++++++++++
 Koha/Edifact/File/Errors.pm                   | 61 +++++++++++++++
 .../swagger/paths/acquisitions_edifiles.yaml  |  1 +
 4 files changed, 156 insertions(+)
 create mode 100644 Koha/Edifact/File/Error.pm
 create mode 100644 Koha/Edifact/File/Errors.pm

diff --git a/Koha/Edifact/File.pm b/Koha/Edifact/File.pm
index 9f24b08f0a8..d71d9e7f231 100644
--- a/Koha/Edifact/File.pm
+++ b/Koha/Edifact/File.pm
@@ -19,6 +19,8 @@ use Modern::Perl;
 
 use base qw(Koha::Object);
 
+use Koha::Edifact::File::Errors;
+
 =encoding utf8
 
 =head1 Name
@@ -57,6 +59,20 @@ sub basket {
     return Koha::Acquisition::Basket->_new_from_dbic($basket_rs);
 }
 
+=head3 errors
+
+  my $errors = $edifile->errors;
+
+Returns any I<Koha::Edifact::File::Errors> associated with this EDIFACT file
+
+=cut
+
+sub errors {
+    my ($self) = @_;
+    my $errors_rs = $self->_result->edifact_errors;
+    return Koha::Edifact::File::Errors->_new_from_dbic($errors_rs);
+}
+
 =head3 to_api_mapping
 
 This method returns the mapping for representing a Koha::Edifact::File object
diff --git a/Koha/Edifact/File/Error.pm b/Koha/Edifact/File/Error.pm
new file mode 100644
index 00000000000..1b8235f515f
--- /dev/null
+++ b/Koha/Edifact/File/Error.pm
@@ -0,0 +1,78 @@
+package Koha::Edifact::File::Error;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use base qw(Koha::Object);
+
+=encoding utf8
+
+=head1 Name
+
+Koha::Edifact::File::Error - Koha::Object class for single EDIFACT file
+
+=head2 Class methods
+
+=head3 file
+
+  my $file = $error->file;
+
+Returns the I<Koha::Edifact::File> associated with this error
+
+=cut
+
+sub file {
+    my ($self) = @_;
+    my $file_rs = $self->_result->message;
+    return unless $file_rs;
+    return Koha::Edifact::File->_new_from_dbic($file_rs);
+}
+
+=head3 to_api_mapping
+
+This method returns the mapping for representing a Koha::Edifact::File::Error object
+on the API.
+
+=cut
+
+sub to_api_mapping {
+    return {
+        message_id => 'file_id',
+    };
+}
+
+=head2 Internal methods
+
+=head3 _type
+
+Returns name of corresponding DBIC resultset
+
+=cut
+
+sub _type {
+    return 'EdifactError';
+}
+
+=head1 AUTHOR
+
+Martin Renvoize <martin.renvoize@ptfs-europe.com>
+
+Koha Development Team
+
+=cut
+
+1;
diff --git a/Koha/Edifact/File/Errors.pm b/Koha/Edifact/File/Errors.pm
new file mode 100644
index 00000000000..7a04f9714cc
--- /dev/null
+++ b/Koha/Edifact/File/Errors.pm
@@ -0,0 +1,61 @@
+package Koha::Edifact::File::Errors;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Koha::Database;
+use Koha::Edifact::File::Error;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::Edifact::File::Errors - Koha Edifact File Error Object set class
+
+=head1 API
+
+=head2 Internal methods
+
+=head3 _type
+
+Returns name of corresponding DBIC resultset
+
+=cut
+
+sub _type {
+    return 'EdifactError';
+}
+
+=head3 object_class
+
+Returns name of corresponding koha object class
+
+=cut
+
+sub object_class {
+    return 'Koha::Edifact::File::Error';
+}
+
+=head1 AUTHOR
+
+Martin Renvoize <martin.renvoize@ptfs-europe.com>
+
+Koha Development Team
+
+=cut
+
+1;
diff --git a/api/v1/swagger/paths/acquisitions_edifiles.yaml b/api/v1/swagger/paths/acquisitions_edifiles.yaml
index 99de6d59491..5f317217261 100644
--- a/api/v1/swagger/paths/acquisitions_edifiles.yaml
+++ b/api/v1/swagger/paths/acquisitions_edifiles.yaml
@@ -26,6 +26,7 @@
           enum:
             - vendor
             - basket
+            - errors
         collectionFormat: csv
 
     responses:
-- 
2.48.0