Bugzilla – Attachment 172855 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), 8.06 KB, created by
Paul Derscheid
on 2024-10-17 10:12:28 UTC
(
hide
)
Description:
Bug 35287: REST API - Add additional fields support to ERM Licenses
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2024-10-17 10:12:28 UTC
Size:
8.06 KB
patch
obsolete
>From 60e65c6ad43e921e6a41d61fcac5b1221ceddba2 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> >Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> >--- > Koha/AdditionalField.pm | 1 + > Koha/REST/V1/ERM/Licenses.pm | 8 +++++ > Koha/REST/V1/ExtendedAttributeTypes.pm | 1 + > Koha/Schema/Result/ErmLicense.pm | 32 +++++++++++++++++++ > api/v1/swagger/definitions/erm_license.yaml | 10 ++++++ > .../definitions/extended_attribute_value.yaml | 18 +++++++++++ > api/v1/swagger/paths/erm_licenses.yaml | 7 ++++ > .../paths/extended_attribute_types.yaml | 1 + > api/v1/swagger/swagger.yaml | 2 ++ > 9 files changed, 80 insertions(+) > create mode 100644 api/v1/swagger/definitions/extended_attribute_value.yaml > >diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm >index a9230ff666..7e5c16a049 100644 >--- a/Koha/AdditionalField.pm >+++ b/Koha/AdditionalField.pm >@@ -59,6 +59,7 @@ sub to_api { > 'accountlines:debit' => 'debit', > 'aqbasket' => 'basket', > 'aqinvoices' => 'invoice', >+ 'erm_licenses' => 'license', > 'aqorders' => 'order', > }; > >diff --git a/Koha/REST/V1/ERM/Licenses.pm b/Koha/REST/V1/ERM/Licenses.pm >index 856386e0c1..1a233761ee 100644 >--- a/Koha/REST/V1/ERM/Licenses.pm >+++ b/Koha/REST/V1/ERM/Licenses.pm >@@ -87,11 +87,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, >@@ -165,11 +169,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/REST/V1/ExtendedAttributeTypes.pm b/Koha/REST/V1/ExtendedAttributeTypes.pm >index c49fddc232..8dfa4ea6ed 100644 >--- a/Koha/REST/V1/ExtendedAttributeTypes.pm >+++ b/Koha/REST/V1/ExtendedAttributeTypes.pm >@@ -50,6 +50,7 @@ sub list { > credit => 'accountlines:credit', > debit => 'accountlines:debit', > invoice => 'aqinvoices', >+ license => 'erm_licenses', > order => 'aqorders', > }; > >diff --git a/Koha/Schema/Result/ErmLicense.pm b/Koha/Schema/Result/ErmLicense.pm >index 17402c0003..bd90014e0d 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/erm_license.yaml b/api/v1/swagger/definitions/erm_license.yaml >index 5a2d43cad8..0bb1222ab5 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: extended_attribute_value.yaml >+ _strings: >+ type: >+ - object >+ - "null" > > additionalProperties: false > required: >diff --git a/api/v1/swagger/definitions/extended_attribute_value.yaml b/api/v1/swagger/definitions/extended_attribute_value.yaml >new file mode 100644 >index 0000000000..3bdfb1acbc >--- /dev/null >+++ b/api/v1/swagger/definitions/extended_attribute_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/paths/erm_licenses.yaml b/api/v1/swagger/paths/erm_licenses.yaml >index 129ce47048..703e2798b8 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 >@@ -173,6 +176,8 @@ > - user_roles.patron > - vendor > - documents >+ - extended_attributes >+ - +strings > collectionFormat: csv > responses: > 200: >@@ -237,6 +242,8 @@ > enum: > - user_roles > - documents >+ - extended_attributes >+ - +strings > collectionFormat: csv > responses: > 200: >diff --git a/api/v1/swagger/paths/extended_attribute_types.yaml b/api/v1/swagger/paths/extended_attribute_types.yaml >index 758703a3c0..7bad73967c 100644 >--- a/api/v1/swagger/paths/extended_attribute_types.yaml >+++ b/api/v1/swagger/paths/extended_attribute_types.yaml >@@ -18,6 +18,7 @@ > - credit > - debit > - invoice >+ - license > - order > - subscription > - $ref: "../swagger.yaml#/parameters/match" >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index dd72361380..b6df49f6ee 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -86,6 +86,8 @@ definitions: > $ref: ./definitions/error.yaml > extended_attribute_type: > $ref: ./definitions/extended_attribute_type.yaml >+ extended_attribute_value: >+ $ref: ./definitions/extended_attribute_value.yaml > fund: > $ref: ./definitions/fund.yaml > hold: >-- >2.47.0
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