Bugzilla – Attachment 143473 Details for
Bug 31028
Add 'Report a concern' feature for patrons to report concerns about catalog records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31028: Add API's for tickets
Bug-31028-Add-APIs-for-tickets.patch (text/plain), 14.98 KB, created by
Martin Renvoize (ashimema)
on 2022-11-09 11:37:46 UTC
(
hide
)
Description:
Bug 31028: Add API's for tickets
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-11-09 11:37:46 UTC
Size:
14.98 KB
patch
obsolete
>From 05c0be1e984987e4788e9e3de7e751a97721d153 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 25 Oct 2022 13:14:19 +0100 >Subject: [PATCH] Bug 31028: Add API's for tickets > >This patch adds basic CRUD API's for the ticket endpoints. >--- > Koha/REST/V1/Tickets.pm | 150 +++++++++++++++ > Koha/Ticket.pm | 13 ++ > api/v1/swagger/definitions/ticket.yaml | 51 +++++ > api/v1/swagger/paths/tickets.yaml | 252 +++++++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 14 ++ > 5 files changed, 480 insertions(+) > create mode 100644 Koha/REST/V1/Tickets.pm > create mode 100644 api/v1/swagger/definitions/ticket.yaml > create mode 100644 api/v1/swagger/paths/tickets.yaml > >diff --git a/Koha/REST/V1/Tickets.pm b/Koha/REST/V1/Tickets.pm >new file mode 100644 >index 0000000000..2e5a418b63 >--- /dev/null >+++ b/Koha/REST/V1/Tickets.pm >@@ -0,0 +1,150 @@ >+package Koha::REST::V1::Tickets; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::Ticket; >+use Koha::Tickets; >+use Koha::Ticket::Update; >+use Koha::Ticket::Updates; >+ >+use Try::Tiny qw( catch try ); >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 list >+ >+=cut >+ >+sub list { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $tickets_set = Koha::Tickets->new; >+ my $tickets = $c->objects->search($tickets_set); >+ return $c->render( status => 200, openapi => $tickets ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+ >+} >+ >+=head3 get >+ >+=cut >+ >+sub get { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') ); >+ unless ($ticket) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Ticket not found" } >+ ); >+ } >+ >+ return $c->render( status => 200, openapi => $ticket->to_api ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ } >+} >+ >+=head3 add >+ >+=cut >+ >+sub add { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $body = $c->validation->param('body'); >+ my $ticket = Koha::Ticket->new_from_api($body)->store; >+ $ticket->discard_changes; >+ $c->res->headers->location( >+ $c->req->url->to_string . '/' . $ticket->id ); >+ return $c->render( >+ status => 201, >+ openapi => $ticket->to_api >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 update >+ >+=cut >+ >+sub update { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') ); >+ >+ if ( not defined $ticket ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ >+ return try { >+ $ticket->set_from_api( $c->validation->param('body') ); >+ $ticket->store(); >+ return $c->render( status => 200, openapi => $ticket->to_api ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 delete >+ >+=cut >+ >+sub delete { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') ); >+ if ( not defined $ticket ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ >+ return try { >+ $ticket->delete; >+ return $c->render( >+ status => 204, >+ openapi => q{} >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+1; >diff --git a/Koha/Ticket.pm b/Koha/Ticket.pm >index 2435d31e38..e557203e23 100644 >--- a/Koha/Ticket.pm >+++ b/Koha/Ticket.pm >@@ -100,6 +100,19 @@ sub add_update { > > =head2 Internal methods > >+=cut >+ >+=head3 to_api_mapping >+ >+This method returns the mapping for representing a Koha::Ticket object >+on the API. >+ >+=cut >+ >+sub to_api_mapping { >+ return { id => 'ticket_id', }; >+} >+ > =head3 _type > > =cut >diff --git a/api/v1/swagger/definitions/ticket.yaml b/api/v1/swagger/definitions/ticket.yaml >new file mode 100644 >index 0000000000..d3439e0443 >--- /dev/null >+++ b/api/v1/swagger/definitions/ticket.yaml >@@ -0,0 +1,51 @@ >+--- >+type: object >+properties: >+ ticket_id: >+ type: integer >+ description: Internal ticket identifier >+ reported_date: >+ type: >+ - string >+ - "null" >+ format: date-time >+ description: Date the ticket was reported >+ biblio: >+ type: >+ - object >+ - "null" >+ description: The object representing the biblio the ticket is related to >+ biblio_id: >+ type: integer >+ description: Internal identifier for the biblio the ticket is related to >+ title: >+ type: string >+ description: Ticket title >+ body: >+ type: string >+ description: Ticket details >+ reporter: >+ type: >+ - object >+ - "null" >+ description: The object representing the patron who reported the ticket >+ reporter_id: >+ type: integer >+ description: Internal identifier for the patron who reported the ticket >+ resolver: >+ type: >+ - object >+ - "null" >+ description: The object representing the user who resolved the ticket >+ resolver_id: >+ type: >+ - integer >+ - "null" >+ description: Internal identifier for the user who resolved the ticket >+ resolved_date: >+ type: >+ - string >+ - "null" >+ format: date-time >+ description: Date the ticket was resolved_date >+additionalProperties: false >diff --git a/api/v1/swagger/paths/tickets.yaml b/api/v1/swagger/paths/tickets.yaml >new file mode 100644 >index 0000000000..ad652a0d78 >--- /dev/null >+++ b/api/v1/swagger/paths/tickets.yaml >@@ -0,0 +1,252 @@ >+--- >+/tickets: >+ get: >+ x-mojo-to: Tickets#list >+ operationId: listTickets >+ tags: >+ - tickets >+ summary: List tickets >+ produces: >+ - application/json >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/match" >+ - $ref: "../swagger.yaml#/parameters/order_by" >+ - $ref: "../swagger.yaml#/parameters/page" >+ - $ref: "../swagger.yaml#/parameters/per_page" >+ - $ref: "../swagger.yaml#/parameters/q_param" >+ - $ref: "../swagger.yaml#/parameters/q_body" >+ - $ref: "../swagger.yaml#/parameters/q_header" >+ - $ref: "../swagger.yaml#/parameters/request_id_header" >+ - name: x-koha-embed >+ in: header >+ required: false >+ description: Embed list sent as a request header >+ type: array >+ items: >+ type: string >+ enum: >+ - reporter >+ - resolver >+ - biblio >+ collectionFormat: csv >+ responses: >+ "200": >+ description: A list of tickets >+ schema: >+ type: array >+ items: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ catalogue: "1" >+ post: >+ x-mojo-to: Tickets#add >+ operationId: addTicket >+ tags: >+ - tickets >+ summary: Add ticket >+ parameters: >+ - name: body >+ in: body >+ description: A JSON object containing informations about the new hold >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Ticket added >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ catalogue: "1" >+"/tickets/{ticket_id}": >+ get: >+ x-mojo-to: Tickets#get >+ operationId: getTicket >+ tags: >+ - tickets >+ summary: Get ticket >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/ticket_id_pp" >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A ticket >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ "404": >+ description: Ticket not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ catalogue: "1" >+ put: >+ x-mojo-to: Tickets#update >+ operationId: updateTicket >+ tags: >+ - tickets >+ summary: Update ticket >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/ticket_id_pp" >+ - name: body >+ in: body >+ description: A ticket object >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A ticket >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Ticket not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: Internal error >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ editcatalogue: edit_catalogue >+ delete: >+ x-mojo-to: Tickets#delete >+ operationId: deleteTicket >+ tags: >+ - tickets >+ summary: Delete ticket >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/ticket_id_pp" >+ produces: >+ - application/json >+ responses: >+ "204": >+ description: Ticket deleted >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Ticket not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: Internal error >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ editcatalogue: edit_catalogue >+/public/tickets: >+ post: >+ x-mojo-to: Tickets#add >+ operationId: addTicketPublic >+ tags: >+ - tickets >+ summary: Add ticket >+ parameters: >+ - name: body >+ in: body >+ description: A JSON object containing informations about the new hold >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Ticket added >+ schema: >+ $ref: "../swagger.yaml#/definitions/ticket" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 696a73be8b..9c763bd21d 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -88,6 +88,8 @@ definitions: > $ref: ./definitions/smtp_server.yaml > suggestion: > $ref: ./definitions/suggestion.yaml >+ ticket: >+ $ref: ./definitions/ticket.yaml > transfer_limit: > $ref: ./definitions/transfer_limit.yaml > vendor: >@@ -291,6 +293,8 @@ paths: > $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_checkouts" > "/public/patrons/{patron_id}/password": > $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1password" >+ "/public/tickets": >+ $ref: "./paths/tickets.yaml#/~1public~1tickets" > /quotes: > $ref: ./paths/quotes.yaml#/~1quotes > "/quotes/{quote_id}": >@@ -311,6 +315,10 @@ paths: > $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}" > /suggestions/managers: > $ref: paths/suggestions.yaml#/~1suggestions~1managers >+ "/tickets": >+ $ref: "./paths/tickets.yaml#/~1tickets" >+ "/tickets/{ticket_id}": >+ $ref: "./paths/tickets.yaml#/~1tickets~1{ticket_id}" > /transfer_limits: > $ref: ./paths/transfer_limits.yaml#/~1transfer_limits > /transfer_limits/batch: >@@ -563,6 +571,12 @@ parameters: > name: suggestion_id > required: true > type: integer >+ ticket_id_pp: >+ description: Internal ticket identifier >+ in: path >+ name: ticket_id >+ required: true >+ type: integer > transfer_limit_id_pp: > description: Internal transfer limit identifier > in: path >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31028
:
137412
|
139222
|
139223
|
139224
|
139225
|
139226
|
139227
|
139228
|
139229
|
139230
|
139231
|
139232
|
139233
|
139234
|
139235
|
139236
|
139237
|
139238
|
139572
|
139573
|
139574
|
139575
|
139576
|
139577
|
139578
|
139579
|
139580
|
139581
|
139582
|
139583
|
139584
|
139585
|
139586
|
139587
|
139588
|
139589
|
139590
|
139591
|
140289
|
140290
|
140291
|
140292
|
140293
|
140294
|
140295
|
140296
|
140297
|
140298
|
140299
|
140300
|
140301
|
140302
|
140303
|
140304
|
140305
|
140306
|
140307
|
140308
|
140436
|
140437
|
140438
|
140439
|
140440
|
140441
|
140442
|
140443
|
140444
|
140445
|
140446
|
140447
|
140448
|
140449
|
140450
|
140451
|
140452
|
140453
|
140454
|
140455
|
140764
|
140765
|
140766
|
140767
|
140768
|
140769
|
140770
|
140771
|
140772
|
140773
|
140774
|
140775
|
140776
|
140777
|
140778
|
140779
|
140780
|
140781
|
140782
|
140783
|
140793
|
140929
|
140930
|
140931
|
140932
|
140933
|
140934
|
140935
|
140936
|
140937
|
140938
|
140939
|
140940
|
140941
|
140942
|
140943
|
140944
|
140945
|
140946
|
140947
|
140948
|
140949
|
140950
|
141133
|
141134
|
141135
|
141136
|
141137
|
141138
|
141139
|
141140
|
141141
|
141142
|
141143
|
141144
|
141145
|
141146
|
141147
|
141148
|
141149
|
141150
|
141151
|
141152
|
141153
|
141154
|
141440
|
141441
|
141442
|
141443
|
141444
|
141445
|
141446
|
141447
|
141448
|
141449
|
141450
|
141451
|
141452
|
141453
|
141454
|
141455
|
141456
|
141457
|
141458
|
141459
|
141460
|
142164
|
142165
|
142166
|
142167
|
142168
|
142169
|
142170
|
142171
|
142172
|
142173
|
142174
|
142175
|
142177
|
142179
|
142180
|
142181
|
142182
|
142183
|
142184
|
142185
|
142186
|
142187
|
142188
|
142189
|
142190
|
142191
|
142616
|
142617
|
142618
|
142619
|
142620
|
142621
|
142622
|
142623
|
142624
|
142625
|
142626
|
142627
|
142932
|
142933
|
142934
|
142935
|
142936
|
142937
|
142938
|
142939
|
142940
|
142941
|
142942
|
142943
|
142944
|
142945
|
142946
|
142947
|
142948
|
142949
|
143238
|
143239
|
143240
|
143241
|
143242
|
143243
|
143244
|
143245
|
143246
|
143247
|
143248
|
143249
|
143250
|
143251
|
143252
|
143253
|
143254
|
143255
|
143256
|
143257
|
143302
|
143303
|
143304
|
143305
|
143306
|
143307
|
143308
|
143309
|
143310
|
143311
|
143312
|
143313
|
143314
|
143315
|
143316
|
143317
|
143318
|
143319
|
143320
|
143321
|
143322
|
143323
|
143324
|
143325
|
143326
|
143327
|
143328
|
143329
|
143330
|
143331
|
143332
|
143333
|
143334
|
143335
|
143336
|
143337
|
143338
|
143339
|
143340
|
143341
|
143470
|
143471
|
143472
|
143473
|
143474
|
143475
|
143476
|
143477
|
143478
|
143479
|
143480
|
143481
|
143482
|
143483
|
143484
|
143485
|
143486
|
143487
|
143488
|
143489
|
143490
|
143647
|
143648
|
143649
|
143650
|
143651
|
143652
|
143653
|
143654
|
143655
|
143656
|
143657
|
143658
|
143659
|
143660
|
143661
|
143662
|
143663
|
143664
|
143665
|
143666
|
143667
|
143708
|
143709
|
143710
|
143711
|
143712
|
143713
|
143714
|
143715
|
143716
|
143717
|
143718
|
143719
|
143720
|
143721
|
143722
|
143723
|
143724
|
143725
|
143726
|
143727
|
144647
|
144648
|
144649
|
144650
|
144651
|
144652
|
144653
|
144654
|
144655
|
144656
|
144657
|
144658
|
144659
|
144660
|
144661
|
144662
|
144663
|
144664
|
144665
|
144666
|
144667
|
144668
|
145542
|
146214
|
146215
|
146216
|
146217
|
146218
|
146219
|
146220
|
146221
|
146222
|
146223
|
146224
|
146225
|
146226
|
146227
|
146228
|
146229
|
146230
|
146231
|
146232
|
146233
|
146234
|
146235
|
146236
|
146237
|
146238
|
146239
|
146240
|
146241
|
146242
|
146243
|
146244
|
146245
|
146246
|
146247
|
146248
|
146249
|
146250
|
146251
|
146252
|
146253
|
146254
|
146255
|
146256
|
146257
|
146258
|
146259
|
146260
|
146261
|
146262
|
146697
|
146870
|
146871
|
146872
|
146873
|
146874
|
146875
|
146876
|
146877
|
146878
|
146879
|
146880
|
146881
|
146882
|
146883
|
146884
|
146885
|
146886
|
146887
|
146888
|
146889
|
146890
|
146891
|
146892
|
146893
|
146894
|
146895
|
146896
|
147797
|
147840
|
147841
|
147844
|
147859
|
147860
|
147861
|
147866
|
148673
|
149931