Bugzilla – Attachment 165642 Details for
Bug 35287
Add additional fields support to ERM licenses
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35287: REST API - Add additional fields support to ERM Licenses
Bug-35287-REST-API---Add-additional-fields-support.patch (text/plain), 6.58 KB, created by
Pedro Amorim
on 2024-04-26 10:32:07 UTC
(
hide
)
Description:
Bug 35287: REST API - Add additional fields support to ERM Licenses
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-04-26 10:32:07 UTC
Size:
6.58 KB
patch
obsolete
>From 7c8ad7fc1534e47871544bd62b82aee4bfecc1fd Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Wed, 8 Nov 2023 11:33:20 -0100 >Subject: [PATCH] Bug 35287: REST API - Add additional fields support to ERM > Licenses > >Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk> >Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> >--- > Koha/REST/V1/ERM/Licenses.pm | 8 +++++ > Koha/Schema/Result/ErmLicense.pm | 32 +++++++++++++++++++ > .../definitions/additional_field_value.yaml | 18 +++++++++++ > api/v1/swagger/definitions/erm_license.yaml | 10 ++++++ > api/v1/swagger/paths/erm_licenses.yaml | 7 ++++ > api/v1/swagger/swagger.yaml | 2 ++ > 6 files changed, 77 insertions(+) > create mode 100644 api/v1/swagger/definitions/additional_field_value.yaml > >diff --git a/Koha/REST/V1/ERM/Licenses.pm b/Koha/REST/V1/ERM/Licenses.pm >index 4e15d703cee..80c1cafe8af 100644 >--- a/Koha/REST/V1/ERM/Licenses.pm >+++ b/Koha/REST/V1/ERM/Licenses.pm >@@ -91,11 +91,15 @@ sub add { > > my $user_roles = delete $body->{user_roles} // []; > my $documents = delete $body->{documents} // []; >+ my $extended_attributes = delete $body->{extended_attributes} // []; > > my $license = Koha::ERM::License->new_from_api($body)->store; > $license->user_roles($user_roles); > $license->documents($documents); > >+ my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; >+ $license->extended_attributes( \@extended_attributes ); >+ > $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); > return $c->render( > status => 201, >@@ -173,11 +177,15 @@ sub update { > > my $user_roles = delete $body->{user_roles} // []; > my $documents = delete $body->{documents} // []; >+ my $extended_attributes = delete $body->{extended_attributes} // []; > > $license->set_from_api($body)->store; > $license->user_roles($user_roles); > $license->documents($documents); > >+ my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; >+ $license->extended_attributes( \@extended_attributes ); >+ > $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); > return $c->render( > status => 200, >diff --git a/Koha/Schema/Result/ErmLicense.pm b/Koha/Schema/Result/ErmLicense.pm >index 17402c00032..bd90014e0d9 100644 >--- a/Koha/Schema/Result/ErmLicense.pm >+++ b/Koha/Schema/Result/ErmLicense.pm >@@ -190,6 +190,38 @@ __PACKAGE__->belongs_to( > # Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-01 07:44:13 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Fs4bmI/N6Cvicv3RW2qwXQ > >+__PACKAGE__->has_many( >+ "additional_field_values", >+ "Koha::Schema::Result::AdditionalFieldValue", >+ sub { >+ my ($args) = @_; >+ >+ return { >+ "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.license_id" }, >+ >+ "$args->{foreign_alias}.field_id" => >+ { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_licenses")' }, >+ }; >+ }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ >+__PACKAGE__->has_many( >+ "extended_attributes", >+ "Koha::Schema::Result::AdditionalFieldValue", >+ sub { >+ my ($args) = @_; >+ >+ return { >+ "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.license_id" }, >+ >+ "$args->{foreign_alias}.field_id" => >+ { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_licenses")' }, >+ }; >+ }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ > sub koha_object_class { > 'Koha::ERM::License'; > } >diff --git a/api/v1/swagger/definitions/additional_field_value.yaml b/api/v1/swagger/definitions/additional_field_value.yaml >new file mode 100644 >index 00000000000..3bdfb1acbc4 >--- /dev/null >+++ b/api/v1/swagger/definitions/additional_field_value.yaml >@@ -0,0 +1,18 @@ >+--- >+type: object >+properties: >+ id: >+ description: id of the field >+ type: string >+ readOnly: true >+ field_id: >+ type: integer >+ description: FK in corresponding to id in additional_fields table >+ record_id: >+ description: ID corresponding to the object ID this additional field relates to >+ type: string >+ value: >+ description: value of the additional field >+ type: string >+ >+additionalProperties: false >\ No newline at end of file >diff --git a/api/v1/swagger/definitions/erm_license.yaml b/api/v1/swagger/definitions/erm_license.yaml >index 5a2d43cad8f..939cbb68bac 100644 >--- a/api/v1/swagger/definitions/erm_license.yaml >+++ b/api/v1/swagger/definitions/erm_license.yaml >@@ -51,6 +51,16 @@ properties: > type: > - object > - "null" >+ extended_attributes: >+ description: Related additional field values >+ type: >+ - array >+ items: >+ $ref: additional_field_value.yaml >+ _strings: >+ type: >+ - object >+ - "null" > > additionalProperties: false > required: >diff --git a/api/v1/swagger/paths/erm_licenses.yaml b/api/v1/swagger/paths/erm_licenses.yaml >index 6dc6c4ebe69..feb347a2532 100644 >--- a/api/v1/swagger/paths/erm_licenses.yaml >+++ b/api/v1/swagger/paths/erm_licenses.yaml >@@ -59,6 +59,9 @@ > type: string > enum: > - vendor >+ - extended_attributes >+ - +strings >+ collectionFormat: csv > responses: > 200: > description: A list of agreements' licenses >@@ -170,6 +173,8 @@ > - user_roles.patron > - vendor > - documents >+ - extended_attributes >+ - +strings > collectionFormat: csv > responses: > 200: >@@ -230,6 +235,8 @@ > enum: > - user_roles > - documents >+ - extended_attributes >+ - +strings > collectionFormat: csv > responses: > 200: >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 593eb8147ab..27ad51a5bff 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -6,6 +6,8 @@ definitions: > $ref: ./definitions/account_line.yaml > additional_field: > $ref: ./definitions/additional_field.yaml >+ additional_field_value: >+ $ref: ./definitions/additional_field_value.yaml > advancededitormacro: > $ref: ./definitions/advancededitormacro.yaml > allows_renewal: >-- >2.39.2
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 35287
:
158725
|
158726
|
158727
|
158728
|
158729
|
158730
|
158731
|
158732
|
158733
|
158734
|
159634
|
159635
|
159636
|
159637
|
159638
|
159639
|
159640
|
159641
|
159642
|
159643
|
165451
|
165637
|
165638
|
165639
|
165640
|
165641
|
165642
|
165643
|
165644
|
165645
|
165646
|
165647
|
167681
|
169728
|
169729
|
169730
|
169731
|
169732
|
169733
|
169734
|
169735
|
169736
|
169737
|
170448
|
170753
|
172850
|
172851
|
172852
|
172853
|
172854
|
172855
|
172856
|
172857
|
172858
|
172860
|
172861
|
173022
|
173102
|
173103
|
173104
|
173105
|
173106
|
173107
|
173108
|
173109
|
173110
|
173111
|
173112
|
173113
|
173290