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

(-)a/Koha/REST/V1/ERM/Licenses.pm (+8 lines)
Lines 91-101 sub add { Link Here
91
91
92
                my $user_roles = delete $body->{user_roles} // [];
92
                my $user_roles = delete $body->{user_roles} // [];
93
                my $documents = delete $body->{documents} // [];
93
                my $documents = delete $body->{documents} // [];
94
                my $extended_attributes = delete $body->{extended_attributes} // [];
94
95
95
                my $license = Koha::ERM::License->new_from_api($body)->store;
96
                my $license = Koha::ERM::License->new_from_api($body)->store;
96
                $license->user_roles($user_roles);
97
                $license->user_roles($user_roles);
97
                $license->documents($documents);
98
                $license->documents($documents);
98
99
100
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
101
                $license->extended_attributes( \@extended_attributes );
102
99
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
103
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
100
                return $c->render(
104
                return $c->render(
101
                    status  => 201,
105
                    status  => 201,
Lines 173-183 sub update { Link Here
173
177
174
                my $user_roles = delete $body->{user_roles} // [];
178
                my $user_roles = delete $body->{user_roles} // [];
175
                my $documents = delete $body->{documents} // [];
179
                my $documents = delete $body->{documents} // [];
180
                my $extended_attributes = delete $body->{extended_attributes} // [];
176
181
177
                $license->set_from_api($body)->store;
182
                $license->set_from_api($body)->store;
178
                $license->user_roles($user_roles);
183
                $license->user_roles($user_roles);
179
                $license->documents($documents);
184
                $license->documents($documents);
180
185
186
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
187
                $license->extended_attributes( \@extended_attributes );
188
181
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
189
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
182
                return $c->render(
190
                return $c->render(
183
                    status  => 200,
191
                    status  => 200,
(-)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/additional_field_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/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: additional_field_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/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 170-175 Link Here
170
            - user_roles.patron
173
            - user_roles.patron
171
            - vendor
174
            - vendor
172
            - documents
175
            - documents
176
            - extended_attributes
177
            - +strings
173
        collectionFormat: csv
178
        collectionFormat: csv
174
    responses:
179
    responses:
175
      200:
180
      200:
Lines 230-235 Link Here
230
          enum:
235
          enum:
231
            - user_roles
236
            - user_roles
232
            - documents
237
            - documents
238
            - extended_attributes
239
            - +strings
233
        collectionFormat: csv
240
        collectionFormat: csv
234
    responses:
241
    responses:
235
      200:
242
      200:
(-)a/api/v1/swagger/swagger.yaml (-1 / +2 lines)
Lines 6-11 definitions: Link Here
6
    $ref: ./definitions/account_line.yaml
6
    $ref: ./definitions/account_line.yaml
7
  additional_field:
7
  additional_field:
8
    $ref: ./definitions/additional_field.yaml
8
    $ref: ./definitions/additional_field.yaml
9
  additional_field_value:
10
    $ref: ./definitions/additional_field_value.yaml
9
  advancededitormacro:
11
  advancededitormacro:
10
    $ref: ./definitions/advancededitormacro.yaml
12
    $ref: ./definitions/advancededitormacro.yaml
11
  allows_renewal:
13
  allows_renewal:
12
- 

Return to bug 35287