1 package Koha::REST::V1::Tickets;
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';
24 use Koha::Ticket::Update;
25 use Koha::Ticket::Updates;
27 use Try::Tiny qw( catch try );
38 my $c = shift->openapi->valid_input or return;
41 my $tickets_set = Koha::Tickets->new;
42 my $tickets = $c->objects->search($tickets_set);
43 return $c->render( status => 200, openapi => $tickets );
46 $c->unhandled_exception($_);
56 my $c = shift->openapi->valid_input or return;
59 my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
63 openapi => { error => "Ticket not found" }
67 return $c->render( status => 200, openapi => $ticket->to_api );
70 $c->unhandled_exception($_);
79 my $c = shift->openapi->valid_input or return;
80 my $patron = $c->stash('koha.user');
83 my $body = $c->validation->param('body');
85 # Set reporter from session
86 $body->{reporter_id} = $patron->id;
87 # FIXME: We should allow impersonation at a later date to
88 # allow an API user to submit on behalf of a user
90 my $ticket = Koha::Ticket->new_from_api($body)->store;
91 $ticket->discard_changes;
92 $c->res->headers->location(
93 $c->req->url->to_string . '/' . $ticket->id );
96 openapi => $ticket->to_api
100 $c->unhandled_exception($_);
109 my $c = shift->openapi->valid_input or return;
111 my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
113 if ( not defined $ticket ) {
116 openapi => { error => "Object not found" }
121 $ticket->set_from_api( $c->validation->param('body') );
123 return $c->render( status => 200, openapi => $ticket->to_api );
126 $c->unhandled_exception($_);
135 my $c = shift->openapi->valid_input or return;
137 my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
138 if ( not defined $ticket ) {
141 openapi => { error => "Object not found" }
153 $c->unhandled_exception($_);