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

(-)a/Koha/REST/V1/Checkout.pm (+54 lines)
Lines 15-20 package Koha::REST::V1::Checkout; Link Here
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
use strict;
19
use warnings;
20
18
use Modern::Perl;
21
use Modern::Perl;
19
22
20
use Mojo::Base 'Mojolicious::Controller';
23
use Mojo::Base 'Mojolicious::Controller';
Lines 22-27 use Mojo::Base 'Mojolicious::Controller'; Link Here
22
use C4::Auth qw( haspermission );
25
use C4::Auth qw( haspermission );
23
use C4::Circulation;
26
use C4::Circulation;
24
use Koha::Issues;
27
use Koha::Issues;
28
use Koha::OldIssues;
25
29
26
sub list {
30
sub list {
27
    my ($c, $args, $cb) = @_;
31
    my ($c, $args, $cb) = @_;
Lines 94-97 sub renew { Link Here
94
    return $c->$cb($checkout->unblessed, 200);
98
    return $c->$cb($checkout->unblessed, 200);
95
}
99
}
96
100
101
sub listhistory {
102
    my ($c, $args, $cb) = @_;
103
104
    my $user = $c->stash('koha.user');
105
    unless ($user && haspermission($user->userid, { circulate => "circulate_remaining_permissions" })) {
106
        return $c->$cb({error => "You don't have the required permission"}, 403);
107
    }
108
109
    my $borrowernumber = $c->param('borrowernumber');
110
111
    my $checkouts;
112
113
    if ($borrowernumber) {
114
115
      $checkouts = Koha::OldIssues->search({
116
        borrowernumber => $borrowernumber
117
      })->unblessed;
118
119
    } else {
120
121
      # Retrieve all the issues in the history, but only the issue_id due to possible perfomance issues
122
      $checkouts = Koha::OldIssues->search({}, {
123
        columns => [qw/issue_id/],
124
      })->unblessed;
125
126
    }
127
128
    $c->$cb($checkouts, 200);
129
}
130
131
sub gethistory {
132
    my ($c, $args, $cb) = @_;
133
134
    my $user = $c->stash('koha.user');
135
    unless ($user && haspermission($user->userid, { circulate => "circulate_remaining_permissions" })) {
136
        return $c->$cb({error => "You don't have the required permission"}, 403);
137
    }
138
139
    my $checkout_id = $args->{checkout_id};
140
    my $checkout = Koha::OldIssues->find($checkout_id);
141
142
    if (!$checkout) {
143
        return $c->$cb({
144
            error => "Checkout doesn't exist"
145
        }, 404);
146
    }
147
148
    return $c->$cb($checkout->unblessed, 200);
149
}
150
97
1;
151
1;
(-)a/api/v1/swagger.json (-1 / +66 lines)
Lines 426-431 Link Here
426
          }
426
          }
427
        }
427
        }
428
      }
428
      }
429
    },
430
    "/checkouts/history": {
431
      "get": {
432
        "operationId": "listhistoryCheckouts",
433
        "tags": ["borrowers", "checkouts"],
434
        "parameters": [
435
          {
436
            "name": "borrowernumber",
437
            "in": "query",
438
            "description": "Internal patron identifier",
439
            "required": false,
440
            "type": "integer"
441
          }
442
        ],
443
        "produces": [
444
          "application/json"
445
        ],
446
        "responses": {
447
          "200": {
448
            "description": "A list of checkouts history",
449
            "schema": {
450
              "$ref": "#/definitions/checkouts"
451
            }
452
          },
453
          "403": {
454
            "description": "Access forbidden",
455
            "schema": { "$ref": "#/definitions/error" }
456
          },
457
          "404": {
458
            "description": "Borrower not found",
459
            "schema": {
460
              "$ref": "#/definitions/error"
461
            }
462
          }
463
        }
464
      }
465
    },
466
    "/checkouts/history/{checkout_id}": {
467
      "get": {
468
        "operationId": "gethistoryCheckout",
469
        "tags": ["borrowers", "checkouts"],
470
        "parameters": [
471
          {
472
            "name": "checkout_id",
473
            "in": "path",
474
            "description": "Internal checkout identifier",
475
            "required": true,
476
            "type": "integer"
477
          }
478
        ],
479
        "produces": ["application/json"],
480
        "responses": {
481
          "200": {
482
            "description": "Got borrower's checkout",
483
            "schema": { "$ref": "#/definitions/checkout" }
484
          },
485
          "403": {
486
            "description": "Access forbidden",
487
            "schema": { "$ref": "#/definitions/error" }
488
          },
489
          "404": {
490
            "description": "Checkout not found",
491
            "schema": { "$ref": "#/definitions/error" }
492
          }
493
        }
494
      }
429
    }
495
    }
430
  },
496
  },
431
  "definitions": {
497
  "definitions": {
432
- 

Return to bug 17005