1 package Koha::REST::V1::Suggestions;
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';
21 use Koha::Suggestions;
27 Koha::REST::V1::Suggestion
35 Controller method that handles listing Koha::Suggestion objects
40 my $c = shift->openapi->valid_input or return;
44 my $suggestions = $c->objects->search( Koha::Suggestions->new );
48 openapi => $suggestions
52 $c->unhandled_exception($_);
58 Controller method that handles retrieving a single Koha::Suggestion object
63 my $c = shift->openapi->valid_input or return;
66 my $suggestion_id = $c->validation->param('suggestion_id');
67 my $suggestion = $c->objects->find( Koha::Suggestions->new, $suggestion_id );
69 unless ($suggestion) {
72 openapi => { error => "Suggestion not found." }
78 openapi => $suggestion
82 $c->unhandled_exception($_);
88 Controller method that handles adding a new Koha::Suggestion object
93 my $c = shift->openapi->valid_input or return;
95 my $body = $c->validation->param('body');
97 # FIXME: This should be handled in Koha::Suggestion->store
98 $body->{'status'} = 'ASKED'
99 unless defined $body->{'status'};
102 my $suggestion = Koha::Suggestion->new_from_api( $body )->store;
103 $suggestion->discard_changes;
104 $c->res->headers->location( $c->req->url->to_string . '/' . $suggestion->suggestionid );
108 openapi => $suggestion->to_api
112 $c->unhandled_exception($_);
118 Controller method that handles modifying Koha::Suggestion object
123 my $c = shift->openapi->valid_input or return;
125 my $suggestion_id = $c->validation->param('suggestion_id');
126 my $suggestion = Koha::Suggestions->find( $suggestion_id );
130 openapi => { error => 'Suggestion not found.' }
131 ) unless $suggestion;
135 my $body = $c->validation->param('body');
137 $suggestion->set_from_api( $body )->store;
138 $suggestion->discard_changes;
142 openapi => $suggestion->to_api
146 $c->unhandled_exception($_);
153 Controller method that handles removing a Koha::Suggestion object
158 my $c = shift->openapi->valid_input or return;
160 my $suggestion_id = $c->validation->param('suggestion_id');
161 my $suggestion = Koha::Suggestions->find( $suggestion_id );
165 openapi => { error => 'Suggestion not found.' }
166 ) unless $suggestion;
176 $c->unhandled_exception($_);