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

Return to bug 40550