View | Details | Raw Unified | Return to bug 31028
Collapse All | Expand All

(-)a/Koha/REST/V1/Tickets.pm (+150 lines)
Line 0 Link Here
1
package Koha::REST::V1::Tickets;
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Ticket;
23
use Koha::Tickets;
24
use Koha::Ticket::Update;
25
use Koha::Ticket::Updates;
26
27
use Try::Tiny qw( catch try );
28
29
=head1 API
30
31
=head2 Methods
32
33
=head3 list
34
35
=cut
36
37
sub list {
38
    my $c = shift->openapi->valid_input or return;
39
40
    return try {
41
        my $tickets_set = Koha::Tickets->new;
42
        my $tickets     = $c->objects->search($tickets_set);
43
        return $c->render( status => 200, openapi => $tickets );
44
    }
45
    catch {
46
        $c->unhandled_exception($_);
47
    };
48
49
}
50
51
=head3 get
52
53
=cut
54
55
sub get {
56
    my $c = shift->openapi->valid_input or return;
57
58
    return try {
59
        my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
60
        unless ($ticket) {
61
            return $c->render(
62
                status  => 404,
63
                openapi => { error => "Ticket not found" }
64
            );
65
        }
66
67
        return $c->render( status => 200, openapi => $ticket->to_api );
68
    }
69
    catch {
70
        $c->unhandled_exception($_);
71
    }
72
}
73
74
=head3 add
75
76
=cut
77
78
sub add {
79
    my $c = shift->openapi->valid_input or return;
80
81
    return try {
82
        my $body   = $c->validation->param('body');
83
        my $ticket = Koha::Ticket->new_from_api($body)->store;
84
        $ticket->discard_changes;
85
        $c->res->headers->location(
86
            $c->req->url->to_string . '/' . $ticket->id );
87
        return $c->render(
88
            status  => 201,
89
            openapi => $ticket->to_api
90
        );
91
    }
92
    catch {
93
        $c->unhandled_exception($_);
94
    };
95
}
96
97
=head3 update
98
99
=cut
100
101
sub update {
102
    my $c = shift->openapi->valid_input or return;
103
104
    my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
105
106
    if ( not defined $ticket ) {
107
        return $c->render(
108
            status  => 404,
109
            openapi => { error => "Object not found" }
110
        );
111
    }
112
113
    return try {
114
        $ticket->set_from_api( $c->validation->param('body') );
115
        $ticket->store();
116
        return $c->render( status => 200, openapi => $ticket->to_api );
117
    }
118
    catch {
119
        $c->unhandled_exception($_);
120
    };
121
}
122
123
=head3 delete
124
125
=cut
126
127
sub delete {
128
    my $c = shift->openapi->valid_input or return;
129
130
    my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
131
    if ( not defined $ticket ) {
132
        return $c->render(
133
            status  => 404,
134
            openapi => { error => "Object not found" }
135
        );
136
    }
137
138
    return try {
139
        $ticket->delete;
140
        return $c->render(
141
            status  => 204,
142
            openapi => q{}
143
        );
144
    }
145
    catch {
146
        $c->unhandled_exception($_);
147
    };
148
}
149
150
1;
(-)a/Koha/Ticket.pm (+13 lines)
Lines 100-105 sub add_update { Link Here
100
100
101
=head2 Internal methods
101
=head2 Internal methods
102
102
103
=cut
104
105
=head3 to_api_mapping
106
107
This method returns the mapping for representing a Koha::Ticket object
108
on the API.
109
110
=cut
111
112
sub to_api_mapping {
113
    return { id => 'ticket_id', };
114
}
115
103
=head3 _type
116
=head3 _type
104
117
105
=cut
118
=cut
(-)a/api/v1/swagger/definitions/ticket.yaml (+51 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  ticket_id:
5
    type: integer
6
    description: Internal ticket identifier
7
  reported_date:
8
    type:
9
      - string
10
      - "null"
11
    format: date-time
12
    description: Date the ticket was reported
13
  biblio:
14
    type:
15
      - object
16
      - "null"
17
    description: The object representing the biblio the ticket is related to
18
  biblio_id:
19
    type: integer
20
    description: Internal identifier for the biblio the ticket is related to
21
  title:
22
    type: string
23
    description: Ticket title
24
  body:
25
    type: string
26
    description: Ticket details
27
  reporter:
28
    type:
29
      - object
30
      - "null"
31
    description: The object representing the patron who reported the ticket
32
  reporter_id:
33
    type: integer
34
    description: Internal identifier for the patron who reported the ticket
35
  resolver:
36
    type:
37
      - object
38
      - "null"
39
    description: The object representing the user who resolved the ticket
40
  resolver_id:
41
    type:
42
      - integer
43
      - "null"
44
    description: Internal identifier for the user who resolved the ticket
45
  resolved_date:
46
    type:
47
      - string
48
      - "null"
49
    format: date-time
50
    description: Date the ticket was resolved_date
51
additionalProperties: false
(-)a/api/v1/swagger/paths/tickets.yaml (+252 lines)
Line 0 Link Here
1
---
2
/tickets:
3
  get:
4
    x-mojo-to: Tickets#list
5
    operationId: listTickets
6
    tags:
7
      - tickets
8
    summary: List tickets
9
    produces:
10
      - application/json
11
    parameters:
12
      - $ref: "../swagger.yaml#/parameters/match"
13
      - $ref: "../swagger.yaml#/parameters/order_by"
14
      - $ref: "../swagger.yaml#/parameters/page"
15
      - $ref: "../swagger.yaml#/parameters/per_page"
16
      - $ref: "../swagger.yaml#/parameters/q_param"
17
      - $ref: "../swagger.yaml#/parameters/q_body"
18
      - $ref: "../swagger.yaml#/parameters/q_header"
19
      - $ref: "../swagger.yaml#/parameters/request_id_header"
20
      - name: x-koha-embed
21
        in: header
22
        required: false
23
        description: Embed list sent as a request header
24
        type: array
25
        items:
26
          type: string
27
          enum:
28
            - reporter
29
            - resolver
30
            - biblio
31
        collectionFormat: csv
32
    responses:
33
      "200":
34
        description: A list of tickets
35
        schema:
36
          type: array
37
          items:
38
            $ref: "../swagger.yaml#/definitions/ticket"
39
      "403":
40
        description: Access forbidden
41
        schema:
42
          $ref: "../swagger.yaml#/definitions/error"
43
      "500":
44
        description: |
45
          Internal server error. Possible `error_code` attribute values:
46
47
          * `internal_server_error`
48
        schema:
49
          $ref: "../swagger.yaml#/definitions/error"
50
      "503":
51
        description: Under maintenance
52
        schema:
53
          $ref: "../swagger.yaml#/definitions/error"
54
    x-koha-authorization:
55
      permissions:
56
        catalogue: "1"
57
  post:
58
    x-mojo-to: Tickets#add
59
    operationId: addTicket
60
    tags:
61
      - tickets
62
    summary: Add ticket
63
    parameters:
64
      - name: body
65
        in: body
66
        description: A JSON object containing informations about the new hold
67
        required: true
68
        schema:
69
          $ref: "../swagger.yaml#/definitions/ticket"
70
    produces:
71
      - application/json
72
    responses:
73
      "201":
74
        description: Ticket added
75
        schema:
76
          $ref: "../swagger.yaml#/definitions/ticket"
77
      "401":
78
        description: Authentication required
79
        schema:
80
          $ref: "../swagger.yaml#/definitions/error"
81
      "403":
82
        description: Access forbidden
83
        schema:
84
          $ref: "../swagger.yaml#/definitions/error"
85
      "500":
86
        description: |
87
          Internal server error. Possible `error_code` attribute values:
88
89
          * `internal_server_error`
90
        schema:
91
          $ref: "../swagger.yaml#/definitions/error"
92
      "503":
93
        description: Under maintenance
94
        schema:
95
          $ref: "../swagger.yaml#/definitions/error"
96
    x-koha-authorization:
97
      permissions:
98
        catalogue: "1"
99
"/tickets/{ticket_id}":
100
  get:
101
    x-mojo-to: Tickets#get
102
    operationId: getTicket
103
    tags:
104
      - tickets
105
    summary: Get ticket
106
    parameters:
107
      - $ref: "../swagger.yaml#/parameters/ticket_id_pp"
108
    produces:
109
      - application/json
110
    responses:
111
      "200":
112
        description: A ticket
113
        schema:
114
          $ref: "../swagger.yaml#/definitions/ticket"
115
      "404":
116
        description: Ticket not found
117
        schema:
118
          $ref: "../swagger.yaml#/definitions/error"
119
      "500":
120
        description: |
121
          Internal server error. Possible `error_code` attribute values:
122
123
          * `internal_server_error`
124
        schema:
125
          $ref: "../swagger.yaml#/definitions/error"
126
      "503":
127
        description: Under maintenance
128
        schema:
129
          $ref: "../swagger.yaml#/definitions/error"
130
    x-koha-authorization:
131
      permissions:
132
        catalogue: "1"
133
  put:
134
    x-mojo-to: Tickets#update
135
    operationId: updateTicket
136
    tags:
137
      - tickets
138
    summary: Update ticket
139
    parameters:
140
      - $ref: "../swagger.yaml#/parameters/ticket_id_pp"
141
      - name: body
142
        in: body
143
        description: A ticket object
144
        required: true
145
        schema:
146
          $ref: "../swagger.yaml#/definitions/ticket"
147
    produces:
148
      - application/json
149
    responses:
150
      "200":
151
        description: A ticket
152
        schema:
153
          $ref: "../swagger.yaml#/definitions/ticket"
154
      "401":
155
        description: Authentication required
156
        schema:
157
          $ref: "../swagger.yaml#/definitions/error"
158
      "403":
159
        description: Access forbidden
160
        schema:
161
          $ref: "../swagger.yaml#/definitions/error"
162
      "404":
163
        description: Ticket not found
164
        schema:
165
          $ref: "../swagger.yaml#/definitions/error"
166
      "500":
167
        description: Internal error
168
        schema:
169
          $ref: "../swagger.yaml#/definitions/error"
170
      "503":
171
        description: Under maintenance
172
        schema:
173
          $ref: "../swagger.yaml#/definitions/error"
174
    x-koha-authorization:
175
      permissions:
176
        editcatalogue: edit_catalogue
177
  delete:
178
    x-mojo-to: Tickets#delete
179
    operationId: deleteTicket
180
    tags:
181
      - tickets
182
    summary: Delete ticket
183
    parameters:
184
      - $ref: "../swagger.yaml#/parameters/ticket_id_pp"
185
    produces:
186
      - application/json
187
    responses:
188
      "204":
189
        description: Ticket deleted
190
      "401":
191
        description: Authentication required
192
        schema:
193
          $ref: "../swagger.yaml#/definitions/error"
194
      "403":
195
        description: Access forbidden
196
        schema:
197
          $ref: "../swagger.yaml#/definitions/error"
198
      "404":
199
        description: Ticket not found
200
        schema:
201
          $ref: "../swagger.yaml#/definitions/error"
202
      "500":
203
        description: Internal error
204
        schema:
205
          $ref: "../swagger.yaml#/definitions/error"
206
      "503":
207
        description: Under maintenance
208
        schema:
209
          $ref: "../swagger.yaml#/definitions/error"
210
    x-koha-authorization:
211
      permissions:
212
        editcatalogue: edit_catalogue
213
/public/tickets:
214
  post:
215
    x-mojo-to: Tickets#add
216
    operationId: addTicketPublic
217
    tags:
218
      - tickets
219
    summary: Add ticket
220
    parameters:
221
      - name: body
222
        in: body
223
        description: A JSON object containing informations about the new hold
224
        required: true
225
        schema:
226
          $ref: "../swagger.yaml#/definitions/ticket"
227
    produces:
228
      - application/json
229
    responses:
230
      "201":
231
        description: Ticket added
232
        schema:
233
          $ref: "../swagger.yaml#/definitions/ticket"
234
      "401":
235
        description: Authentication required
236
        schema:
237
          $ref: "../swagger.yaml#/definitions/error"
238
      "403":
239
        description: Access forbidden
240
        schema:
241
          $ref: "../swagger.yaml#/definitions/error"
242
      "500":
243
        description: |
244
          Internal server error. Possible `error_code` attribute values:
245
246
          * `internal_server_error`
247
        schema:
248
          $ref: "../swagger.yaml#/definitions/error"
249
      "503":
250
        description: Under maintenance
251
        schema:
252
          $ref: "../swagger.yaml#/definitions/error"
(-)a/api/v1/swagger/swagger.yaml (-1 / +14 lines)
Lines 74-79 definitions: Link Here
74
    $ref: ./definitions/smtp_server.yaml
74
    $ref: ./definitions/smtp_server.yaml
75
  suggestion:
75
  suggestion:
76
    $ref: ./definitions/suggestion.yaml
76
    $ref: ./definitions/suggestion.yaml
77
  ticket:
78
    $ref: ./definitions/ticket.yaml
77
  transfer_limit:
79
  transfer_limit:
78
    $ref: ./definitions/transfer_limit.yaml
80
    $ref: ./definitions/transfer_limit.yaml
79
  vendor:
81
  vendor:
Lines 237-242 paths: Link Here
237
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
239
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts"
238
  "/public/patrons/{patron_id}/password":
240
  "/public/patrons/{patron_id}/password":
239
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1password"
241
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1password"
242
  "/public/tickets":
243
    $ref: "./paths/tickets.yaml#/~1public~1tickets"
240
  /quotes:
244
  /quotes:
241
    $ref: ./paths/quotes.yaml#/~1quotes
245
    $ref: ./paths/quotes.yaml#/~1quotes
242
  "/quotes/{quote_id}":
246
  "/quotes/{quote_id}":
Lines 257-262 paths: Link Here
257
    $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}"
261
    $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}"
258
  /suggestions/managers:
262
  /suggestions/managers:
259
    $ref: paths/suggestions.yaml#/~1suggestions~1managers
263
    $ref: paths/suggestions.yaml#/~1suggestions~1managers
264
  "/tickets":
265
    $ref: "./paths/tickets.yaml#/~1tickets"
266
  "/tickets/{ticket_id}":
267
    $ref: "./paths/tickets.yaml#/~1tickets~1{ticket_id}"
260
  /transfer_limits:
268
  /transfer_limits:
261
    $ref: ./paths/transfer_limits.yaml#/~1transfer_limits
269
    $ref: ./paths/transfer_limits.yaml#/~1transfer_limits
262
  /transfer_limits/batch:
270
  /transfer_limits/batch:
Lines 461-466 parameters: Link Here
461
    name: suggestion_id
469
    name: suggestion_id
462
    required: true
470
    required: true
463
    type: integer
471
    type: integer
472
  ticket_id_pp:
473
    description: Internal ticket identifier
474
    in: path
475
    name: ticket_id
476
    required: true
477
    type: integer
464
  transfer_limit_id_pp:
478
  transfer_limit_id_pp:
465
    description: Internal transfer limit identifier
479
    description: Internal transfer limit identifier
466
    in: path
480
    in: path
467
- 

Return to bug 31028