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

(-)a/Koha/REST/V1/Holds.pm (+44 lines)
Lines 340-345 sub delete { Link Here
340
    };
340
    };
341
}
341
}
342
342
343
=head3 delete_bulk
344
345
Method that handles deleting multiple Koha::Hold objects
346
347
=cut
348
349
sub delete_bulk {
350
    my $c = shift->openapi->valid_input or return;
351
352
    my $body                = $c->req->json;
353
    my $hold_ids            = ($body) ? $body->{hold_ids}            : undef;
354
    my $cancellation_reason = ($body) ? $body->{cancellation_reason} : undef;
355
356
    return $c->render_resource_not_found("Hold")
357
        unless $hold_ids;
358
359
    foreach my $hold_id (@$hold_ids) {
360
        my $hold = Koha::Holds->find($hold_id);
361
        return $c->render_resource_not_found( "Hold", "id", $hold_id )
362
            unless $hold;
363
    }
364
365
    return try {
366
        Koha::Database->new->schema->txn_do(
367
            sub {
368
                foreach my $hold_id (@$hold_ids) {
369
                    my $hold = Koha::Holds->find($hold_id);
370
                    $hold->cancel( { cancellation_reason => $cancellation_reason } );
371
                }
372
                $c->res->headers->location( $c->req->url->to_string );
373
                return $c->render(
374
                    status  => 204,
375
                    openapi => {
376
                        hold_ids            => $hold_ids,
377
                        cancellation_reason => $cancellation_reason,
378
                    }
379
                );
380
            }
381
        );
382
    } catch {
383
        $c->unhandled_exception($_);
384
    };
385
}
386
343
=head3 suspend
387
=head3 suspend
344
388
345
Method that handles suspending a hold
389
Method that handles suspending a hold
(-)a/api/v1/swagger/paths/holds.yaml (+58 lines)
Lines 340-345 Link Here
340
    x-koha-authorization:
340
    x-koha-authorization:
341
      permissions:
341
      permissions:
342
        reserveforothers: place_holds
342
        reserveforothers: place_holds
343
"/holds/cancellation_bulk":
344
  delete:
345
    x-mojo-to: Holds#delete_bulk
346
    operationId: deleteHolds
347
    tags:
348
      - holds
349
    summary: Cancel holds
350
    parameters:
351
      - name: body
352
        in: body
353
        description: Hold ids
354
        required: true
355
        schema:
356
          type: object
357
          properties:
358
            cancellation_reason:
359
              description: Cancellation reason
360
              type: string
361
            hold_ids:
362
              type: array
363
              items:
364
                type: integer
365
          additionalProperties: false
366
    produces:
367
      - application/json
368
    responses:
369
      "204":
370
        description: Holds deleted
371
      "400":
372
        description: Bad request
373
        schema:
374
          $ref: "../swagger.yaml#/definitions/error"
375
      "401":
376
        description: Authentication required
377
        schema:
378
          $ref: "../swagger.yaml#/definitions/error"
379
      "403":
380
        description: Hold not allowed
381
        schema:
382
          $ref: "../swagger.yaml#/definitions/error"
383
      "404":
384
        description: Hold not found
385
        schema:
386
          $ref: "../swagger.yaml#/definitions/error"
387
      "500":
388
        description: |
389
          Internal server error. Possible `error_code` attribute values:
390
391
          * `internal_server_error`
392
        schema:
393
          $ref: "../swagger.yaml#/definitions/error"
394
      "503":
395
        description: Under maintenance
396
        schema:
397
          $ref: "../swagger.yaml#/definitions/error"
398
    x-koha-authorization:
399
      permissions:
400
        reserveforothers: place_holds
343
"/holds/{hold_id}":
401
"/holds/{hold_id}":
344
  patch:
402
  patch:
345
    x-mojo-to: Holds#edit
403
    x-mojo-to: Holds#edit
(-)a/api/v1/swagger/swagger.yaml (-1 / +2 lines)
Lines 405-410 paths: Link Here
405
    $ref: ./paths/holds.yaml#/~1holds
405
    $ref: ./paths/holds.yaml#/~1holds
406
  "/holds/suspension_bulk":
406
  "/holds/suspension_bulk":
407
    $ref: "./paths/holds.yaml#/~1holds~1suspension_bulk"
407
    $ref: "./paths/holds.yaml#/~1holds~1suspension_bulk"
408
  "/holds/cancellation_bulk":
409
    $ref: "./paths/holds.yaml#/~1holds~1cancellation_bulk"
408
  "/holds/{hold_id}":
410
  "/holds/{hold_id}":
409
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}"
411
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}"
410
  "/holds/{hold_id}/pickup_location":
412
  "/holds/{hold_id}/pickup_location":
411
- 

Return to bug 40550