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

(-)a/Koha/REST/V1/CirculationRules.pm (+77 lines)
Lines 178-181 sub list_rules { Link Here
178
    };
178
    };
179
}
179
}
180
180
181
sub set_rules {
182
    my $c = shift->openapi->valid_input or return;
183
184
    return try {
185
        my $body = $c->req->json;
186
187
        my $item_type       = $body->{context}->{item_type_id};
188
        my $branchcode      = $body->{context}->{library_id};
189
        my $patron_category = $body->{context}->{patron_category_id};
190
191
        if ( $item_type eq '*' ) {
192
            $item_type = undef;
193
        } else {
194
            my $type = Koha::ItemTypes->find($item_type);
195
            return $c->render_invalid_parameter_value(
196
                {
197
                    path   => '/body/context/item_type_id',
198
                    values => {
199
                        uri   => '/api/v1/item_types',
200
                        field => 'item_type_id'
201
                    }
202
                }
203
            ) unless $type;
204
        }
205
206
        if ( $branchcode eq '*' ) {
207
            $branchcode = undef;
208
        } else {
209
            my $library = Koha::Libraries->find($branchcode);
210
            return $c->render_invalid_parameter_value(
211
                {
212
                    path   => '/body/context/library_id',
213
                    values => {
214
                        uri   => '/api/v1/libraries',
215
                        field => 'library_id'
216
                    }
217
                }
218
            ) unless $library;
219
        }
220
221
        if ( $patron_category eq '*' ) {
222
            $patron_category = undef;
223
        } else {
224
            my $category = Koha::Patron::Categories->find($patron_category);
225
            return $c->render_invalid_parameter_value(
226
                {
227
                    path   => '/body/context/patron_category_id',
228
                    values => {
229
                        uri   => '/api/v1/patron_categories',
230
                        field => 'patron_category_id'
231
                    }
232
                }
233
            ) unless $category;
234
        }
235
236
        my $rules = %{$body};
237
        delete $rules->{context};
238
239
        my $new_rules = Koha::CirculationRules->set_rules(
240
            $body->{rules},
241
            {
242
                categorycode => $patron_category,
243
                itemtype     => $item_type,
244
                branchcode   => $branchcode
245
            }
246
        );
247
248
        my $return = { map { $_->rule_name => $_->rule_value } @{$new_rules} };
249
        $return->{context} = { library_id => $branchcode, patron_category_id => $patron_category, item_type_id => $item_type };
250
251
        return $c->render(
252
            status  => 200,
253
            openapi => $return
254
        );
255
    }
256
}
257
181
1;
258
1;
(-)a/api/v1/swagger/paths/circulation_rules.yaml (-1 / +54 lines)
Lines 67-72 Link Here
67
    x-koha-authorization:
67
    x-koha-authorization:
68
      permissions:
68
      permissions:
69
        - circulate: circulate_remaining_permissions
69
        - circulate: circulate_remaining_permissions
70
  put:
71
    x-mojo-to: CirculationRules#set_rules
72
    operationId: setCirculationRules
73
    tags:
74
      - circulation_rules
75
    summary: Update circulation rules
76
    parameters:
77
      - name: body
78
        in: body
79
        description: A JSON object containing new information about circulation rules
80
        required: true
81
        schema:
82
          $ref: "../swagger.yaml#/definitions/circulation_rules"
83
    consumes:
84
      - application/json
85
    produces:
86
      - application/json
87
    responses:
88
      "200":
89
        description: A successfully updated circulation rules set
90
        schema:
91
          items:
92
            $ref: "../swagger.yaml#/definitions/circulation_rules"
93
      "400":
94
        description: |
95
          Bad request.
96
        schema:
97
          $ref: "../swagger.yaml#/definitions/error"
98
      "403":
99
        description: Access forbidden
100
        schema:
101
          $ref: "../swagger.yaml#/definitions/error"
102
      "404":
103
        description: Resource not found
104
        schema:
105
          $ref: "../swagger.yaml#/definitions/error"
106
      "409":
107
        description: Conflict in updating resource
108
        schema:
109
          $ref: "../swagger.yaml#/definitions/error"
110
      "500":
111
        description: |
112
          Internal server error. Possible `error_code` attribute values:
113
114
          * `internal_server_error`
115
        schema:
116
          $ref: "../swagger.yaml#/definitions/error"
117
      "503":
118
        description: Under maintenance
119
        schema:
120
          $ref: "../swagger.yaml#/definitions/error"
121
    x-koha-authorization:
122
      permissions:
123
        - circulate: circulate_remaining_permissions
70
/circulation_rules/kinds:
124
/circulation_rules/kinds:
71
  get:
125
  get:
72
    x-mojo-to: CirculationRules#get_kinds
126
    x-mojo-to: CirculationRules#get_kinds
73
- 

Return to bug 37256