View | Details | Raw Unified | Return to bug 35287
Collapse All | Expand All

(-)a/Koha/AdditionalField.pm (+1 lines)
Lines 59-64 sub to_api { Link Here
59
        'accountlines:debit'  => 'debit',
59
        'accountlines:debit'  => 'debit',
60
        'aqbasket'            => 'basket',
60
        'aqbasket'            => 'basket',
61
        'aqinvoices'          => 'invoice',
61
        'aqinvoices'          => 'invoice',
62
        'erm_licenses'        => 'license',
62
        'aqorders'            => 'order',
63
        'aqorders'            => 'order',
63
    };
64
    };
64
65
(-)a/Koha/REST/V1/ERM/Licenses.pm (+8 lines)
Lines 87-97 sub add { Link Here
87
87
88
                my $user_roles = delete $body->{user_roles} // [];
88
                my $user_roles = delete $body->{user_roles} // [];
89
                my $documents = delete $body->{documents} // [];
89
                my $documents = delete $body->{documents} // [];
90
                my $extended_attributes = delete $body->{extended_attributes} // [];
90
91
91
                my $license = Koha::ERM::License->new_from_api($body)->store;
92
                my $license = Koha::ERM::License->new_from_api($body)->store;
92
                $license->user_roles($user_roles);
93
                $license->user_roles($user_roles);
93
                $license->documents($documents);
94
                $license->documents($documents);
94
95
96
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
97
                $license->extended_attributes( \@extended_attributes );
98
95
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
99
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
96
                return $c->render(
100
                return $c->render(
97
                    status  => 201,
101
                    status  => 201,
Lines 165-175 sub update { Link Here
165
169
166
                my $user_roles = delete $body->{user_roles} // [];
170
                my $user_roles = delete $body->{user_roles} // [];
167
                my $documents = delete $body->{documents} // [];
171
                my $documents = delete $body->{documents} // [];
172
                my $extended_attributes = delete $body->{extended_attributes} // [];
168
173
169
                $license->set_from_api($body)->store;
174
                $license->set_from_api($body)->store;
170
                $license->user_roles($user_roles);
175
                $license->user_roles($user_roles);
171
                $license->documents($documents);
176
                $license->documents($documents);
172
177
178
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
179
                $license->extended_attributes( \@extended_attributes );
180
173
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
181
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
174
                return $c->render(
182
                return $c->render(
175
                    status  => 200,
183
                    status  => 200,
(-)a/Koha/REST/V1/ExtendedAttributeTypes.pm (+1 lines)
Lines 50-55 sub list { Link Here
50
        credit  => 'accountlines:credit',
50
        credit  => 'accountlines:credit',
51
        debit   => 'accountlines:debit',
51
        debit   => 'accountlines:debit',
52
        invoice => 'aqinvoices',
52
        invoice => 'aqinvoices',
53
        license => 'erm_licenses',
53
        order   => 'aqorders',
54
        order   => 'aqorders',
54
    };
55
    };
55
56
(-)a/Koha/Schema/Result/ErmLicense.pm (+32 lines)
Lines 190-195 __PACKAGE__->belongs_to( Link Here
190
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-01 07:44:13
190
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-01 07:44:13
191
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Fs4bmI/N6Cvicv3RW2qwXQ
191
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Fs4bmI/N6Cvicv3RW2qwXQ
192
192
193
__PACKAGE__->has_many(
194
    "additional_field_values",
195
    "Koha::Schema::Result::AdditionalFieldValue",
196
    sub {
197
        my ($args) = @_;
198
199
        return {
200
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.license_id" },
201
202
            "$args->{foreign_alias}.field_id" =>
203
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_licenses")' },
204
        };
205
    },
206
    { cascade_copy => 0, cascade_delete => 0 },
207
);
208
209
__PACKAGE__->has_many(
210
    "extended_attributes",
211
    "Koha::Schema::Result::AdditionalFieldValue",
212
    sub {
213
        my ($args) = @_;
214
215
        return {
216
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.license_id" },
217
218
            "$args->{foreign_alias}.field_id" =>
219
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_licenses")' },
220
        };
221
    },
222
    { cascade_copy => 0, cascade_delete => 0 },
223
);
224
193
sub koha_object_class {
225
sub koha_object_class {
194
    'Koha::ERM::License';
226
    'Koha::ERM::License';
195
}
227
}
(-)a/api/v1/swagger/definitions/erm_license.yaml (+10 lines)
Lines 51-56 properties: Link Here
51
    type:
51
    type:
52
      - object
52
      - object
53
      - "null"
53
      - "null"
54
  extended_attributes:
55
    description: Related additional field values
56
    type:
57
      - array
58
    items:
59
      $ref: extended_attribute_value.yaml
60
  _strings:
61
    type:
62
      - object
63
      - "null"
54
64
55
additionalProperties: false
65
additionalProperties: false
56
required:
66
required:
(-)a/api/v1/swagger/definitions/extended_attribute_value.yaml (+18 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  id:
5
    description: id of the field
6
    type: string
7
    readOnly: true
8
  field_id:
9
    type: integer
10
    description: FK in corresponding to id in additional_fields table
11
  record_id:
12
    description: ID corresponding to the object ID this additional field relates to
13
    type: string
14
  value:
15
    description: value of the additional field
16
    type: string
17
18
additionalProperties: false
(-)a/api/v1/swagger/paths/erm_licenses.yaml (+7 lines)
Lines 59-64 Link Here
59
          type: string
59
          type: string
60
          enum:
60
          enum:
61
            - vendor
61
            - vendor
62
            - extended_attributes
63
            - +strings
64
        collectionFormat: csv
62
    responses:
65
    responses:
63
      200:
66
      200:
64
        description: A list of agreements' licenses
67
        description: A list of agreements' licenses
Lines 173-178 Link Here
173
            - user_roles.patron
176
            - user_roles.patron
174
            - vendor
177
            - vendor
175
            - documents
178
            - documents
179
            - extended_attributes
180
            - +strings
176
        collectionFormat: csv
181
        collectionFormat: csv
177
    responses:
182
    responses:
178
      200:
183
      200:
Lines 237-242 Link Here
237
          enum:
242
          enum:
238
            - user_roles
243
            - user_roles
239
            - documents
244
            - documents
245
            - extended_attributes
246
            - +strings
240
        collectionFormat: csv
247
        collectionFormat: csv
241
    responses:
248
    responses:
242
      200:
249
      200:
(-)a/api/v1/swagger/paths/extended_attribute_types.yaml (+1 lines)
Lines 18-23 Link Here
18
          - credit
18
          - credit
19
          - debit
19
          - debit
20
          - invoice
20
          - invoice
21
          - license
21
          - order
22
          - order
22
          - subscription
23
          - subscription
23
      - $ref: "../swagger.yaml#/parameters/match"
24
      - $ref: "../swagger.yaml#/parameters/match"
(-)a/api/v1/swagger/swagger.yaml (-1 / +2 lines)
Lines 86-91 definitions: Link Here
86
    $ref: ./definitions/error.yaml
86
    $ref: ./definitions/error.yaml
87
  extended_attribute_type:
87
  extended_attribute_type:
88
    $ref: ./definitions/extended_attribute_type.yaml
88
    $ref: ./definitions/extended_attribute_type.yaml
89
  extended_attribute_value:
90
    $ref: ./definitions/extended_attribute_value.yaml
89
  fund:
91
  fund:
90
    $ref: ./definitions/fund.yaml
92
    $ref: ./definitions/fund.yaml
91
  hold:
93
  hold:
92
- 

Return to bug 35287