1 package Koha::REST::V1::SearchFilter;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Mojo::Base 'Mojolicious::Controller';
20 use Koha::SearchFilters;
22 use Try::Tiny qw( catch try );
26 Koha::REST::V1::SearchFilters
34 Controller function that handles listing Koha::SearchFilter objects
39 my $c = shift->openapi->valid_input or return;
41 my $filters_set = Koha::SearchFilters->search({});
42 my $filters = $c->objects->search( $filters_set );
49 $c->unhandled_exception($_);
56 Controller function that handles retrieving a single Koha::AdvancedEditorMacro
61 my $c = shift->openapi->valid_input or return;
62 my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
64 return $c->render( status => 404,
65 openapi => { error => "Search filter not found" } );
68 return $c->render( status => 200, openapi => $filter->to_api );
73 Controller function that handles adding a new Koha::SearchFilter object
78 my $c = shift->openapi->valid_input or return;
81 my $filter = Koha::SearchFilter->new_from_api( $c->validation->param('body') );
82 $filter->store->discard_changes;
83 $c->res->headers->location( $c->req->url->to_string . '/' . $filter->id );
86 openapi => $filter->to_api
90 if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
93 openapi => { error => $_->error, conflict => $_->duplicate_id }
96 $c->unhandled_exception($_);
102 Controller function that handles updating a Koha::SearchFilter object
107 my $c = shift->openapi->valid_input or return;
109 my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
111 if ( not defined $filter ) {
112 return $c->render( status => 404,
113 openapi => { error => "Object not found" } );
117 my $params = $c->req->json;
118 $filter->set_from_api( $params );
119 $filter->store->discard_changes;
120 return $c->render( status => 200, openapi => $filter->to_api );
123 $c->unhandled_exception($_);
129 Controller function that handles deleting a Koha::SearchFilter object
134 my $c = shift->openapi->valid_input or return;
136 my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
137 if ( not defined $filter ) {
138 return $c->render( status => 404,
139 openapi => { error => "Object not found" } );
144 return $c->render( status => 204, openapi => q{} );
147 $c->unhandled_exception($_);