From ecef48accbd7ff1573ecb3e0e7ece90174ff6e52 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 20 Dec 2023 16:14:53 +0000 Subject: [PATCH] Bug 34324: Add support for additional fields to /tickets We need to store page_url as part of the opac_report functionality. Rather than adding fields to the core tickets table, it makes sense to utilise the additional_fields functionality. --- Koha/REST/V1/Tickets.pm | 10 ++++++++++ Koha/Ticket.pm | 2 +- api/v1/swagger/definitions/ticket.yaml | 7 +++++++ api/v1/swagger/paths/tickets.yaml | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Tickets.pm b/Koha/REST/V1/Tickets.pm index 5fca8e443b1..9fc6b2225ec 100644 --- a/Koha/REST/V1/Tickets.pm +++ b/Koha/REST/V1/Tickets.pm @@ -82,8 +82,18 @@ sub add { # FIXME: We should allow impersonation at a later date to # allow an API user to submit on behalf of a user + # Capture additional_fields + my $extended_attributes = delete $body->{extended_attributes} // []; + + # Create ticket my $ticket = Koha::Ticket->new_from_api($body)->store; $ticket->discard_changes; + + # Set additional_fields + my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; + $ticket->extended_attributes(\@extended_attributes); + + # Respond $c->res->headers->location( $c->req->url->to_string . '/' . $ticket->id ); return $c->render( diff --git a/Koha/Ticket.pm b/Koha/Ticket.pm index 18f9c672a39..d28a51c3b04 100644 --- a/Koha/Ticket.pm +++ b/Koha/Ticket.pm @@ -17,7 +17,7 @@ package Koha::Ticket; use Modern::Perl; -use base qw(Koha::Object); +use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields); use C4::Letters; diff --git a/api/v1/swagger/definitions/ticket.yaml b/api/v1/swagger/definitions/ticket.yaml index 47c366bb784..e3e0fe73f15 100644 --- a/api/v1/swagger/definitions/ticket.yaml +++ b/api/v1/swagger/definitions/ticket.yaml @@ -9,6 +9,7 @@ properties: type: string enum: - catalog + - opac_problem reported_date: type: - string @@ -76,6 +77,12 @@ properties: - integer - "null" description: Number of updates + extended_attributes: + type: + - array + items: + $ref: additional_field_value.yaml + description: Related additional field values _strings: type: - object diff --git a/api/v1/swagger/paths/tickets.yaml b/api/v1/swagger/paths/tickets.yaml index c3010dfafa6..828a1c0594e 100644 --- a/api/v1/swagger/paths/tickets.yaml +++ b/api/v1/swagger/paths/tickets.yaml @@ -30,6 +30,7 @@ - biblio - updates+count - +strings + - extended_attributes collectionFormat: csv responses: "200": -- 2.47.0