From a3060956ce80a18061572f99081111ddd09196b1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 10 Nov 2023 12:44:36 +0000 Subject: [PATCH] Bug 30070: Add fetch endpoint for EDI Files This patch adds a simple EDI Files listing REST endpoint Signed-off-by: Ray Delahunty Signed-off-by: Kyle M Hall --- Koha/Edifact/File.pm | 42 +++++++++++++ Koha/Edifact/Files.pm | 3 +- .../V1/Acquisitions/Vendor/Edifact/Files.pm | 63 +++++++++++++++++++ api/v1/swagger/definitions/edifact_file.yaml | 63 +++++++++++++++++++ .../swagger/paths/acquisitions_edifiles.yaml | 63 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 ++ 6 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm create mode 100644 api/v1/swagger/definitions/edifact_file.yaml create mode 100644 api/v1/swagger/paths/acquisitions_edifiles.yaml diff --git a/Koha/Edifact/File.pm b/Koha/Edifact/File.pm index 8f01f1dff3e..8e9cea555cd 100644 --- a/Koha/Edifact/File.pm +++ b/Koha/Edifact/File.pm @@ -27,6 +27,48 @@ Koha::Edifact::File - Koha::Object class for single edifact file =head2 Class methods +=head3 vendor + + my $vendor = $edifile->vendor; + +Returns the I associated with this edifact file + +=cut + +sub vendor { + my ($self) = @_; + my $vendor_rs = $self->_result->vendor; + return Koha::Acquisition::Bookseller->_new_from_dbic( $vendor_rs ); +} + +=head3 basket + + my $basket = $edifile->basket; + +Returns the I associated with this edifact file. + +=cut + +sub basket { + my ( $self ) = @_; + my $basket_rs = $self->_result->basketno; + return Koha::Acquisition::Basket->_new_from_dbic( $basket_rs ); +} + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Edifact::File object +on the API. + +=cut + +sub to_api_mapping { + return { + message_type => 'type', + basketno => 'basket_id', + }; +} + =head2 Internal methods =head3 _type diff --git a/Koha/Edifact/Files.pm b/Koha/Edifact/Files.pm index e0701d24794..05da72db316 100644 --- a/Koha/Edifact/Files.pm +++ b/Koha/Edifact/Files.pm @@ -18,6 +18,7 @@ package Koha::Edifact::Files; use Modern::Perl; use Koha::Database; +use Koha::Edifact::File; use base qw(Koha::Objects); @@ -27,8 +28,6 @@ Koha::Edifact::Files - Koha Edifact File Object set class =head1 API -=head2 Class Methods - =head2 Internal methods =head3 _type diff --git a/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm b/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm new file mode 100644 index 00000000000..1f4ae3fc09e --- /dev/null +++ b/Koha/REST/V1/Acquisitions/Vendor/Edifact/Files.pm @@ -0,0 +1,63 @@ +package Koha::REST::V1::Acquisitions::Vendor::Edifact::Files; + +# 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 . + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use Koha::Edifact::Files; + +use Try::Tiny qw( catch try ); + +=head1 NAME + +Koha::REST::V1::Acquisitions::Edifact::Files + +=head1 API + +=head2 Class methods + +=head3 list + +Controller function that handles edifact files + +=cut + +=head3 list + +Return the list of edifact files + +=cut + +sub list { + my $c = shift->openapi->valid_input or return; + + return try { + + my $files_rs = Koha::Edifact::Files->new; + my $files = $c->objects->search($files_rs); + + return $c->render( + status => 200, + openapi => $files, + ); + } catch { + $c->unhandled_exception($_); + }; +} + +1; diff --git a/api/v1/swagger/definitions/edifact_file.yaml b/api/v1/swagger/definitions/edifact_file.yaml new file mode 100644 index 00000000000..4f32fbe4cdc --- /dev/null +++ b/api/v1/swagger/definitions/edifact_file.yaml @@ -0,0 +1,63 @@ +--- +type: object +properties: + id: + type: integer + description: internally assigned edifect file identifier + readOnly: true + type: + type: + - string + description: Edifact file type + transfer_date: + type: + - string + - "null" + format: date + description: Edifact file transfer date + vendor_id: + type: + - string + - "null" + description: Koha vendor id + vendor: + type: + - object + - "null" + description: Koha vendor + edi_acct: + type: + - string + - "null" + description: Edifact account + status: + type: + - string + - "null" + description: Edifact file status + basket_id: + type: + - string + - "null" + description: Koha basket id + basket: + type: + - object + - "null" + description: Koha basket + raw_msg: + type: + - string + - "null" + description: Edifact message + filename: + type: + - string + - "null" + description: Edifact file name + deleted: + type: + - boolean + - "null" + description: Is this file deleted +additionalProperties: false diff --git a/api/v1/swagger/paths/acquisitions_edifiles.yaml b/api/v1/swagger/paths/acquisitions_edifiles.yaml new file mode 100644 index 00000000000..c7968fcde35 --- /dev/null +++ b/api/v1/swagger/paths/acquisitions_edifiles.yaml @@ -0,0 +1,63 @@ +--- +/acquisitions/edifiles: + get: + x-mojo-to: Acquisitions::Vendor::Edifact::Files#list + operationId: listEdifactFiles + tags: + - edifiles + summary: List edifact files + produces: + - application/json + parameters: + - $ref: "../swagger.yaml#/parameters/match" + - $ref: "../swagger.yaml#/parameters/order_by" + - $ref: "../swagger.yaml#/parameters/page" + - $ref: "../swagger.yaml#/parameters/per_page" + - $ref: "../swagger.yaml#/parameters/q_param" + - $ref: "../swagger.yaml#/parameters/q_body" + - $ref: "../swagger.yaml#/parameters/request_id_header" + - name: x-koha-embed + in: header + required: false + description: Embed list sent as a request header + type: array + items: + type: string + enum: + - vendor + - basket + collectionFormat: csv + + responses: + "200": + description: A list of edifact files + schema: + type: array + items: + $ref: "../swagger.yaml#/definitions/edifact_file" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: Edifile not found + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + acquisition: edi_manage diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 46966e40b2b..227921d7957 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -38,6 +38,8 @@ definitions: $ref: ./definitions/credit.yaml debit: $ref: ./definitions/debit.yaml + edifact_file: + $ref: ./definitions/edifact_file.yaml erm_config: $ref: ./definitions/erm_config.yaml erm_agreement: @@ -163,6 +165,8 @@ definitions: paths: /acquisitions/baskets/managers: $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers + /acquisitions/edifiles: + $ref: ./paths/acquisitions_edifiles.yaml#/~1acquisitions~1edifiles /acquisitions/funds: $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds /acquisitions/funds/owners: -- 2.41.0