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: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Pedro Amorim 2023-11-08 11:33:20 -01:00 committed by Katrin Fischer
parent 4dd77d4207
commit b22ebef5cd
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
9 changed files with 80 additions and 0 deletions

View File

@ -59,6 +59,7 @@ sub to_api {
'accountlines:debit' => 'debit',
'aqbasket' => 'basket',
'aqinvoices' => 'invoice',
'erm_licenses' => 'license',
'aqorders' => 'order',
};

View File

@ -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,

View File

@ -50,6 +50,7 @@ sub list {
credit => 'accountlines:credit',
debit => 'accountlines:debit',
invoice => 'aqinvoices',
license => 'erm_licenses',
order => 'aqorders',
};

View File

@ -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';
}

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -18,6 +18,7 @@
- credit
- debit
- invoice
- license
- order
- subscription
- $ref: "../swagger.yaml#/parameters/match"

View File

@ -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: