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

(-)a/Koha/REST/V1/Patrons/Holds.pm (+34 lines)
Lines 63-68 sub list { Link Here
63
    };
63
    };
64
}
64
}
65
65
66
=head3 list_old
67
68
Controller function that handles listing Koha::Old::Hold objects for the requested patron
69
70
=cut
71
72
sub list_old {
73
    my $c = shift->openapi->valid_input or return;
74
75
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
76
77
    unless ( $patron ) {
78
        return $c->render(
79
            status  => 404,
80
            openapi => {
81
                error => 'Patron not found'
82
            }
83
        );
84
    }
85
86
    return try {
87
88
        my $holds = $c->objects->search( $patron->old_holds );
89
90
        return $c->render(
91
            status  => 200,
92
            openapi => $holds
93
        );
94
    }
95
    catch {
96
        $c->unhandled_exception($_);
97
    };
98
}
99
66
100
67
=head3 delete_public
101
=head3 delete_public
68
102
(-)a/api/v1/swagger/paths/patrons_holds.yaml (+61 lines)
Lines 60-62 Link Here
60
    x-koha-authorization:
60
    x-koha-authorization:
61
      permissions:
61
      permissions:
62
        borrowers: edit_borrowers
62
        borrowers: edit_borrowers
63
"/patrons/{patron_id}/holds/previous":
64
  get:
65
    x-mojo-to: Patrons::Holds#list_old
66
    operationId: getPatronHoldsPrevious
67
    tags:
68
      - holds
69
    summary: List previous holds for a patron
70
    parameters:
71
      - $ref: "../swagger.yaml#/parameters/patron_id_pp"
72
      - $ref: "../swagger.yaml#/parameters/match"
73
      - $ref: "../swagger.yaml#/parameters/order_by"
74
      - $ref: "../swagger.yaml#/parameters/page"
75
      - $ref: "../swagger.yaml#/parameters/per_page"
76
      - $ref: "../swagger.yaml#/parameters/q_param"
77
      - $ref: "../swagger.yaml#/parameters/q_body"
78
      - $ref: "../swagger.yaml#/parameters/request_id_header"
79
      - name: x-koha-embed
80
        in: header
81
        required: false
82
        description: Embed list sent as a request header
83
        type: array
84
        items:
85
          type: string
86
          enum:
87
            - cancellation_requested
88
          collectionFormat: csv
89
    produces:
90
      - application/json
91
    responses:
92
      "200":
93
        description: The patron holds
94
        schema:
95
          type: array
96
          items:
97
            $ref: "../swagger.yaml#/definitions/hold"
98
      "401":
99
        description: Authentication required
100
        schema:
101
          $ref: "../swagger.yaml#/definitions/error"
102
      "403":
103
        description: Access forbidden
104
        schema:
105
          $ref: "../swagger.yaml#/definitions/error"
106
      "404":
107
        description: Patron not found
108
        schema:
109
          $ref: "../swagger.yaml#/definitions/error"
110
      "500":
111
        description: |
112
          Internal server error. Possible `error_code` attribute values:
113
114
          * `internal_server_error`
115
        schema:
116
          $ref: "../swagger.yaml#/definitions/error"
117
      "503":
118
        description: Under maintenance
119
        schema:
120
          $ref: "../swagger.yaml#/definitions/error"
121
    x-koha-authorization:
122
      permissions:
123
        borrowers: edit_borrowers
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 419-424 paths: Link Here
419
    $ref: "./paths/patrons_extended_attributes.yaml#/~1patrons~1{patron_id}~1extended_attributes~1{extended_attribute_id}"
419
    $ref: "./paths/patrons_extended_attributes.yaml#/~1patrons~1{patron_id}~1extended_attributes~1{extended_attribute_id}"
420
  "/patrons/{patron_id}/holds":
420
  "/patrons/{patron_id}/holds":
421
    $ref: "./paths/patrons_holds.yaml#/~1patrons~1{patron_id}~1holds"
421
    $ref: "./paths/patrons_holds.yaml#/~1patrons~1{patron_id}~1holds"
422
  "/patrons/{patron_id}/holds/previous":
423
    $ref: "./paths/patrons_holds.yaml#/~1patrons~1{patron_id}~1holds~1previous"
422
  "/patrons/{patron_id}/password":
424
  "/patrons/{patron_id}/password":
423
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
425
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
424
  "/patrons/{patron_id}/password/expiration_date":
426
  "/patrons/{patron_id}/password/expiration_date":
(-)a/t/db_dependent/api/v1/patrons_holds.t (-2 / +46 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 3;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
23
Lines 70-75 subtest 'list() tests' => sub { Link Here
70
    $schema->storage->txn_rollback;
70
    $schema->storage->txn_rollback;
71
};
71
};
72
72
73
subtest 'list_old() tests' => sub {
74
75
    plan tests => 9;
76
77
    $schema->storage->txn_begin;
78
79
    my $patron = $builder->build_object({
80
        class => 'Koha::Patrons',
81
        value => { flags => 2 ** 4 } # 'borrowers' flag == 4
82
    });
83
    my $password = 'thePassword123';
84
    $patron->set_password({ password => $password, skip_validation => 1 });
85
    my $userid = $patron->userid;
86
87
    $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds/previous')
88
      ->status_is( 200, 'SWAGGER3.2.2' )
89
      ->json_is( [] );
90
91
    my $hold_1 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
92
    $hold_1->cancel();
93
    my $cancellationdate = $hold_1->cancellationdate;
94
    $cancellationdate =~ s/ \d\d:\d\d:\d\d//;
95
    $hold_1->cancellationdate( $cancellationdate );
96
    my $hold_2 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
97
    $hold_2->cancel();
98
    $cancellationdate = $hold_2->cancellationdate;
99
    $cancellationdate =~ s/ \d\d:\d\d:\d\d//;
100
    $hold_2->cancellationdate( $cancellationdate );
101
102
    $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds/previous?_order_by=+me.hold_id')
103
      ->status_is( 200, 'SWAGGER3.2.2' )
104
      ->json_is( '' => [ $hold_1->to_api, $hold_2->to_api ], 'Holds retrieved' );
105
106
    my $non_existent_patron = $builder->build_object({ class => 'Koha::Patrons' });
107
    my $non_existent_patron_id = $non_existent_patron->id;
108
    # get rid of the patron
109
    $non_existent_patron->delete;
110
111
    $t->get_ok("//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/holds/previous')
112
      ->status_is( 404 )
113
      ->json_is( '/error' => 'Patron not found' );
114
115
    $schema->storage->txn_rollback;
116
};
117
73
subtest 'delete_public() tests' => sub {
118
subtest 'delete_public() tests' => sub {
74
119
75
    plan tests => 13;
120
    plan tests => 13;
76
- 

Return to bug 35353