1 package Koha::REST::V1::ERM::CounterFiles;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Mojo::Base 'Mojolicious::Controller';
22 use Koha::ERM::CounterFiles;
24 use Scalar::Util qw( blessed );
25 use Try::Tiny qw( catch try );
36 my $c = shift->openapi->valid_input or return;
39 my $counter_files_set = Koha::ERM::CounterFiles->new;
40 my $counter_files = $c->objects->search($counter_files_set);
41 return $c->render( status => 200, openapi => $counter_files );
44 $c->unhandled_exception($_);
51 Controller function that handles retrieving a single Koha::ERM::CounterFile object
56 my $c = shift->openapi->valid_input or return;
59 my $counter_file_id = $c->validation->param('erm_counter_files_id');
61 # Do not use $c->objects->find here, we need the file_content
62 my $counter_file = Koha::ERM::CounterFiles->find($counter_file_id);
64 if ( !$counter_file ) {
67 openapi => { error => "Counter file not found" }
72 'data' => $counter_file->file_content,
73 'filename' => $counter_file->filename . '.csv'
77 $c->unhandled_exception($_);
86 my $c = shift->openapi->valid_input or return;
88 my $counter_file_id = $c->validation->param('erm_counter_files_id');
89 my $counter_file = Koha::ERM::CounterFiles->find($counter_file_id);
90 unless ($counter_file) {
93 openapi => { error => "Counter file not found" }
98 $counter_file->delete;
105 $c->unhandled_exception($_);