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 343-348 Link Here
343
    x-koha-authorization:
343
    x-koha-authorization:
344
      permissions:
344
      permissions:
345
        reserveforothers: place_holds
345
        reserveforothers: place_holds
346
"/holds/cancellation_bulk":
347
  delete:
348
    x-mojo-to: Holds#delete_bulk
349
    operationId: deleteHolds
350
    tags:
351
      - holds
352
    summary: Cancel holds
353
    parameters:
354
      - name: body
355
        in: body
356
        description: Hold ids
357
        required: true
358
        schema:
359
          type: object
360
          properties:
361
            cancellation_reason:
362
              description: Cancellation reason
363
              type: string
364
            hold_ids:
365
              type: array
366
              items:
367
                type: integer
368
          additionalProperties: false
369
    produces:
370
      - application/json
371
    responses:
372
      "204":
373
        description: Holds deleted
374
      "400":
375
        description: Bad request
376
        schema:
377
          $ref: "../swagger.yaml#/definitions/error"
378
      "401":
379
        description: Authentication required
380
        schema:
381
          $ref: "../swagger.yaml#/definitions/error"
382
      "403":
383
        description: Hold not allowed
384
        schema:
385
          $ref: "../swagger.yaml#/definitions/error"
386
      "404":
387
        description: Hold not found
388
        schema:
389
          $ref: "../swagger.yaml#/definitions/error"
390
      "500":
391
        description: |
392
          Internal server error. Possible `error_code` attribute values:
393
394
          * `internal_server_error`
395
        schema:
396
          $ref: "../swagger.yaml#/definitions/error"
397
      "503":
398
        description: Under maintenance
399
        schema:
400
          $ref: "../swagger.yaml#/definitions/error"
401
    x-koha-authorization:
402
      permissions:
403
        reserveforothers: place_holds
346
"/holds/{hold_id}":
404
"/holds/{hold_id}":
347
  patch:
405
  patch:
348
    x-mojo-to: Holds#edit
406
    x-mojo-to: Holds#edit
(-)a/api/v1/swagger/swagger.yaml (-1 / +2 lines)
Lines 413-418 paths: Link Here
413
    $ref: ./paths/holds.yaml#/~1holds
413
    $ref: ./paths/holds.yaml#/~1holds
414
  "/holds/suspension_bulk":
414
  "/holds/suspension_bulk":
415
    $ref: "./paths/holds.yaml#/~1holds~1suspension_bulk"
415
    $ref: "./paths/holds.yaml#/~1holds~1suspension_bulk"
416
  "/holds/cancellation_bulk":
417
    $ref: "./paths/holds.yaml#/~1holds~1cancellation_bulk"
416
  "/holds/{hold_id}":
418
  "/holds/{hold_id}":
417
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}"
419
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}"
418
  "/holds/{hold_id}/pickup_location":
420
  "/holds/{hold_id}/pickup_location":
419
- 

Return to bug 40550