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

(-)a/Koha/REST/V1/Checkouts.pm (+34 lines)
Lines 420-423 sub allows_renewal { Link Here
420
    };
420
    };
421
}
421
}
422
422
423
=head3 get
424
425
count checkout
426
427
=cut
428
429
sub count {
430
    my $c = shift->openapi->valid_input or return;
431
432
    my $checked_in = $c->param('checked_in');
433
    $c->req->params->remove('checked_in');
434
435
    try {
436
        my $checkouts_set;
437
438
        if ( $checked_in ) {
439
            $checkouts_set = Koha::Old::Checkouts->new;
440
        } else {
441
            $checkouts_set = Koha::Checkouts->new;
442
        }
443
444
        my $count = {
445
            'count' => scalar(@{ $c->objects->search( $checkouts_set ) })
446
        };
447
448
        return $c->render(
449
            status  => 200,
450
            openapi => $count
451
        );
452
    } catch {
453
        $c->unhandled_exception($_);
454
    };
455
}
456
423
1;
457
1;
(-)a/api/v1/swagger/definitions/count.yaml (+6 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  count:
5
    type: string
6
    description: Number of entity that match the request
(-)a/api/v1/swagger/paths/checkouts.yaml (+51 lines)
Lines 414-416 Link Here
414
          $ref: "../swagger.yaml#/definitions/error"
414
          $ref: "../swagger.yaml#/definitions/error"
415
    x-koha-authorization:
415
    x-koha-authorization:
416
      allow-owner: true
416
      allow-owner: true
417
"/checkouts/count":
418
  get:
419
    x-mojo-to: Checkouts#count
420
    operationId: countCheckouts
421
    tags:
422
      - checkouts
423
    summary: Count checkouts
424
    parameters:
425
      - $ref: "../swagger.yaml#/parameters/patron_id_qp"
426
      - $ref: "../swagger.yaml#/parameters/page"
427
      - $ref: "../swagger.yaml#/parameters/per_page"
428
      - $ref: "../swagger.yaml#/parameters/match"
429
      - $ref: "../swagger.yaml#/parameters/order_by"
430
      - $ref: "../swagger.yaml#/parameters/q_param"
431
      - $ref: "../swagger.yaml#/parameters/q_body"
432
      - $ref: "../swagger.yaml#/parameters/request_id_header"
433
      - name: checked_in
434
        in: query
435
        description: By default, current checkouts are returned, when this is true then
436
          checked in checkouts are returned as result.
437
        type: boolean
438
    produces:
439
      - application/json
440
    responses:
441
      "200":
442
        description: Count of checkouts
443
        schema:
444
          $ref: "../swagger.yaml#/definitions/count"
445
      "403":
446
        description: Access forbidden
447
        schema:
448
          $ref: "../swagger.yaml#/definitions/error"
449
      "404":
450
        description: Not found
451
        schema:
452
          $ref: "../swagger.yaml#/definitions/error"
453
      "500":
454
        description: |
455
          Internal server error. Possible `error_code` attribute values:
456
457
          * `internal_server_error`
458
        schema:
459
          $ref: "../swagger.yaml#/definitions/error"
460
      "503":
461
        description: Under maintenance
462
        schema:
463
          $ref: "../swagger.yaml#/definitions/error"
464
    x-koha-authorization:
465
      permissions:
466
        - circulate: circulate_remaining_permissions
467
        - circulate: manage_bookings
(-)a/api/v1/swagger/swagger.yaml (+4 lines)
Lines 162-167 definitions: Link Here
162
    $ref: ./definitions/vendor.yaml
162
    $ref: ./definitions/vendor.yaml
163
  vendor_issue:
163
  vendor_issue:
164
    $ref: ./definitions/vendor_issue.yaml
164
    $ref: ./definitions/vendor_issue.yaml
165
  count:
166
    $ref: ./definitions/count.yaml
165
paths:
167
paths:
166
  /acquisitions/baskets/managers:
168
  /acquisitions/baskets/managers:
167
    $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers
169
    $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers
Lines 263-268 paths: Link Here
263
    $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal"
265
    $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal"
264
  "/checkouts/availability":
266
  "/checkouts/availability":
265
    $ref: "./paths/checkouts.yaml#/~1checkouts~1availability"
267
    $ref: "./paths/checkouts.yaml#/~1checkouts~1availability"
268
  "/checkouts/count":
269
    $ref: "./paths/checkouts.yaml#/~1checkouts~1count"
266
  /circulation-rules/kinds:
270
  /circulation-rules/kinds:
267
    $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds
271
    $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds
268
  /cities:
272
  /cities:
(-)a/t/db_dependent/api/v1/checkouts.t (-2 / +19 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 108;
20
use Test::More tests => 120;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 61-71 my $patron_id = $patron->borrowernumber; Link Here
61
61
62
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
62
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
63
63
64
$t->get_ok( "//$userid:$password@/api/v1/checkouts/count?patron_id=$patron_id" )
65
  ->status_is(200)
66
  ->json_is('/count' => 0);
67
64
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id" )
68
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id" )
65
  ->status_is(200)
69
  ->status_is(200)
66
  ->json_is([]);
70
  ->json_is([]);
67
71
68
my $notexisting_patron_id = $patron_id + 1;
72
my $notexisting_patron_id = $patron_id + 1;
73
$t->get_ok( "//$userid:$password@/api/v1/checkouts/count?patron_id=$notexisting_patron_id" )
74
  ->status_is(200)
75
  ->json_is('/count' => 0);
76
69
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$notexisting_patron_id" )
77
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$notexisting_patron_id" )
70
  ->status_is(200)
78
  ->status_is(200)
71
  ->json_is([]);
79
  ->json_is([]);
Lines 120-125 my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due ); Link Here
120
my $issue4 = C4::Circulation::AddIssue($patron, $item4->barcode);
128
my $issue4 = C4::Circulation::AddIssue($patron, $item4->barcode);
121
C4::Circulation::AddReturn($item4->barcode, $branchcode);
129
C4::Circulation::AddReturn($item4->barcode, $branchcode);
122
130
131
$t->get_ok( "//$userid:$password@/api/v1/checkouts/count?patron_id=$patron_id" )
132
  ->status_is(200)
133
  ->json_is('/count' => 2);
134
123
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id" )
135
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id" )
124
  ->status_is(200)
136
  ->status_is(200)
125
  ->json_is('/0/patron_id' => $patron_id)
137
  ->json_is('/0/patron_id' => $patron_id)
Lines 160-165 $t->get_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->is Link Here
160
              required_permissions => { circulate => "circulate_remaining_permissions" }
172
              required_permissions => { circulate => "circulate_remaining_permissions" }
161
            });
173
            });
162
174
175
$t->get_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/count?patron_id=$patron_id")
176
    ->status_is(403)->json_is({
177
        error                => "Authorization failure. Missing required permission(s).",
178
        required_permissions => [{"circulate" => "circulate_remaining_permissions"}, {"circulate" => "manage_bookings"}]
179
    });
180
163
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id")
181
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id")
164
  ->status_is(200)
182
  ->status_is(200)
165
  ->json_is('/0/patron_id' => $patron_id)
183
  ->json_is('/0/patron_id' => $patron_id)
166
- 

Return to bug 36562