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

(-)a/Koha/REST/V1/Patrons/Recalls.pm (+63 lines)
Line 0 Link Here
1
package Koha::REST::V1::Patrons::Recalls;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Patrons;
23
24
=head1 NAME
25
26
Koha::REST::V1::Patrons::Recalls
27
28
=head1 API
29
30
=head2 Methods
31
32
=head3 list
33
34
Controller function that handles listing Koha::Recall objects for the requested patron
35
36
=cut
37
38
sub list {
39
    my $c = shift->openapi->valid_input or return;
40
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
42
43
    unless ($patron) {
44
        return $c->render(
45
            status  => 404,
46
            openapi => { error => 'Patron not found' }
47
        );
48
    }
49
50
    return try {
51
52
        my $recalls = $c->objects->search( $patron->recalls );
53
54
        return $c->render(
55
            status  => 200,
56
            openapi => $recalls
57
        );
58
    } catch {
59
        $c->unhandled_exception($_);
60
    };
61
}
62
63
1;
(-)a/api/v1/swagger/definitions/recall.yaml (+81 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  recall_id:
5
    type: integer
6
    description: Internal recall identifier
7
  patron_id:
8
    type: integer
9
    description: Internal patron identifier
10
  created_date:
11
    type:
12
      - string
13
      - "null"
14
    format: date-time
15
    description: The date the recall was requested
16
  biblio_id:
17
    type: integer
18
    description: Internal biblio identifier
19
  pickup_library_id:
20
    type:
21
      - string
22
      - "null"
23
    description: Internal library identifier for the pickup library
24
  completed_date:
25
    type:
26
      - string
27
      - "null"
28
    format: date-time
29
    description: The date the recall was fulfilled
30
  notes:
31
    type:
32
      - string
33
      - "null"
34
    description: Notes related to this recall
35
  priority:
36
    type:
37
      - integer
38
      - "null"
39
    description: Where in the queue the patron sits (not yet implemented)
40
  status:
41
    type:
42
      - string
43
      - "null"
44
    description: Status of the recall
45
    enum:
46
      - requested
47
      - overdue
48
      - waiting
49
      - in_transit
50
      - cancelled
51
      - expired
52
      - fulfilled
53
  timestamp:
54
    type: string
55
    format: date-time
56
    description: Timestamp for the latest recall update
57
  item_id:
58
    type:
59
      - integer
60
      - "null"
61
    description: Internal item identifier
62
  waiting_date:
63
    type:
64
      - string
65
      - "null"
66
    format: date-time
67
    description: The date the item was marked as waiting for the patron at the library
68
  expiration_date:
69
    type:
70
      - string
71
      - "null"
72
    format: date-time
73
    description: The date the recall expires
74
  completed:
75
    type: boolean
76
    description: Controls if the recall is fulfilled
77
  item_level:
78
    type: boolean
79
    description: If the recall is requested at item level
80
81
additionalProperties: false
(-)a/api/v1/swagger/definitions/recalls.yaml (+5 lines)
Line 0 Link Here
1
---
2
type: array
3
items:
4
  $ref: "recall.yaml"
5
additionalProperties: false
(-)a/api/v1/swagger/paths/patrons_recalls.yaml (+52 lines)
Line 0 Link Here
1
---
2
"/patrons/{patron_id}/recalls":
3
  get:
4
    x-mojo-to: Patrons::Recalls#list
5
    operationId: getPatronRecalls
6
    tags:
7
      - recalls
8
    summary: List recalls for a patron
9
    parameters:
10
      - $ref: "../swagger.yaml#/parameters/patron_id_pp"
11
      - $ref: "../swagger.yaml#/parameters/match"
12
      - $ref: "../swagger.yaml#/parameters/order_by"
13
      - $ref: "../swagger.yaml#/parameters/page"
14
      - $ref: "../swagger.yaml#/parameters/per_page"
15
      - $ref: "../swagger.yaml#/parameters/q_param"
16
      - $ref: "../swagger.yaml#/parameters/q_body"
17
      - $ref: "../swagger.yaml#/parameters/request_id_header"
18
    produces:
19
      - application/json
20
    responses:
21
      "200":
22
        description: The patron's recalls
23
        schema:
24
          type: array
25
          items:
26
            $ref: "../swagger.yaml#/definitions/recall"
27
      "401":
28
        description: Authentication required
29
        schema:
30
          $ref: "../swagger.yaml#/definitions/error"
31
      "403":
32
        description: Access forbidden
33
        schema:
34
          $ref: "../swagger.yaml#/definitions/error"
35
      "404":
36
        description: Patron not found
37
        schema:
38
          $ref: "../swagger.yaml#/definitions/error"
39
      "500":
40
        description: |
41
          Internal server error. Possible `error_code` attribute values:
42
43
          * `internal_server_error`
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
46
      "503":
47
        description: Under maintenance
48
        schema:
49
          $ref: "../swagger.yaml#/definitions/error"
50
    x-koha-authorization:
51
      permissions:
52
        recalls: manage_recalls
(-)a/api/v1/swagger/swagger.yaml (+9 lines)
Lines 140-145 definitions: Link Here
140
    $ref: ./definitions/preservation_processing.yaml
140
    $ref: ./definitions/preservation_processing.yaml
141
  quote:
141
  quote:
142
    $ref: ./definitions/quote.yaml
142
    $ref: ./definitions/quote.yaml
143
  recall:
144
    $ref: ./definitions/recall.yaml
145
  recalls:
146
    $ref: ./definitions/recalls.yaml
143
  renewal:
147
  renewal:
144
    $ref: ./definitions/renewal.yaml
148
    $ref: ./definitions/renewal.yaml
145
  renewals:
149
  renewals:
Lines 427-432 paths: Link Here
427
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
431
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
428
  "/patrons/{patron_id}/password/expiration_date":
432
  "/patrons/{patron_id}/password/expiration_date":
429
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
433
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
434
  "/patrons/{patron_id}/recalls":
435
    $ref: "./paths/patrons_recalls.yaml#/~1patrons~1{patron_id}~1recalls"
430
  /preservation/config:
436
  /preservation/config:
431
    $ref: ./paths/preservation_config.yaml#/~1preservation~1config
437
    $ref: ./paths/preservation_config.yaml#/~1preservation~1config
432
  /preservation/trains:
438
  /preservation/trains:
Lines 1146-1151 tags: Link Here
1146
  - description: "Manage quotes\n"
1152
  - description: "Manage quotes\n"
1147
    name: quotes
1153
    name: quotes
1148
    x-displayName: Quotes
1154
    x-displayName: Quotes
1155
  - description: "Manage recalls\n"
1156
    name: recalls
1157
    x-displayName: Recalls
1149
  - description: "Manage return claims\n"
1158
  - description: "Manage return claims\n"
1150
    name: return_claims
1159
    name: return_claims
1151
    x-displayName: Return claims
1160
    x-displayName: Return claims
(-)a/t/db_dependent/api/v1/patrons_recalls.t (-1 / +71 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use Test::Mojo;
22
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
26
use Koha::Database;
27
28
my $schema  = Koha::Database->new->schema;
29
my $builder = t::lib::TestBuilder->new();
30
31
my $t = Test::Mojo->new('Koha::REST::V1');
32
33
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
34
35
subtest 'list() tests' => sub {
36
37
    plan tests => 9;
38
39
    $schema->storage->txn_begin;
40
41
    my $patron = $builder->build_object(
42
        {
43
            class => 'Koha::Patrons',
44
            value => { flags => 2**27 }    # recalls flag == 27
45
        }
46
    );
47
    my $password = 'thePassword123';
48
    $patron->set_password( { password => $password, skip_validation => 1 } );
49
    my $userid = $patron->userid;
50
51
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/recalls' )->status_is( 200, 'SWAGGER3.2.2' )
52
        ->json_is( [] );
53
54
    my $recall_1 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } );
55
    my $recall_2 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } );
56
57
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/recalls?_order_by=+me.recall_id' )
58
        ->status_is( 200, 'SWAGGER3.2.2' )
59
        ->json_is( '' => [ $recall_1->to_api, $recall_2->to_api ], 'Recalls retrieved' );
60
61
    my $non_existent_patron    = $builder->build_object( { class => 'Koha::Patrons' } );
62
    my $non_existent_patron_id = $non_existent_patron->id;
63
64
    # get rid of the patron
65
    $non_existent_patron->delete;
66
67
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/recalls' )->status_is(404)
68
        ->json_is( '/error' => 'Patron not found' );
69
70
    $schema->storage->txn_rollback;
71
};

Return to bug 35967