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

(-)a/Koha/REST/V1/Recalls.pm (+47 lines)
Line 0 Link Here
1
package Koha::REST::V1::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 Mojo::JSON;
23
24
use Koha::Recalls;
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 list
31
32
Method that handles listing Koha::Recall objects
33
34
=cut
35
36
sub list {
37
    my $c = shift->openapi->valid_input or return;
38
39
    return try {
40
        my $recalls = $c->objects->search( Koha::Recalls->new );
41
        return $c->render( status => 200, openapi => $recalls );
42
    } catch {
43
        $c->unhandled_exception($_);
44
    };
45
}
46
47
1;
(-)a/api/v1/swagger/paths/recalls.yaml (+111 lines)
Line 0 Link Here
1
---
2
/recalls:
3
  get:
4
    x-mojo-to: Recalls#list
5
    operationId: listRecalls
6
    tags:
7
      - recalls
8
    summary: List recalls
9
    parameters:
10
      - name: recall_id
11
        in: query
12
        description: Internal recall identifier
13
        type: integer
14
      - name: patron_id
15
        in: query
16
        description: Internal patron identifier
17
        type: integer
18
      - name: created_date
19
        in: query
20
        description: The date the recall was requested
21
        type: string
22
      - name: biblio_id
23
        in: query
24
        description: Internal biblio identifier
25
        type: integer
26
      - name: pickup_library_id
27
        in: query
28
        description: Internal library identifier for the pickup library
29
        type: string
30
      - name: waiting_date
31
        in: query
32
        description: The date the item was marked as waiting for the patron at the library
33
        type: string
34
      - name: expiration_date
35
        in: query
36
        description: The date the recall expires
37
        type: string
38
      - name: completed_date
39
        in: query
40
        description: The date the recall was fulfilled
41
        type: string
42
      - name: notes
43
        in: query
44
        description: Notes related to this recall
45
        type: string
46
      - name: priority
47
        in: query
48
        description: Where in the queue the patron sits (not yet implemented)
49
        type: integer
50
      - name: status
51
        in: query
52
        description: Status of the recall
53
        type: string
54
      - name: timestamp
55
        in: query
56
        description: Timestamp for the latest recall update
57
        type: string
58
      - name: item_id
59
        in: query
60
        description: Internal item identifier
61
        type: integer
62
      - name: completed
63
        in: query
64
        description: Controls if the recall is fulfilled
65
        type: boolean
66
      - name: item_level
67
        in: query
68
        description: If the recall is requested at item level
69
        type: boolean
70
      - $ref: "../swagger.yaml#/parameters/match"
71
      - $ref: "../swagger.yaml#/parameters/order_by"
72
      - $ref: "../swagger.yaml#/parameters/page"
73
      - $ref: "../swagger.yaml#/parameters/per_page"
74
      - $ref: "../swagger.yaml#/parameters/q_param"
75
      - $ref: "../swagger.yaml#/parameters/q_body"
76
      - $ref: "../swagger.yaml#/parameters/request_id_header"
77
    produces:
78
      - application/json
79
    responses:
80
      "200":
81
        description: The patron's recalls
82
        schema:
83
          type: array
84
          items:
85
            $ref: "../swagger.yaml#/definitions/recall"
86
      "401":
87
        description: Authentication required
88
        schema:
89
          $ref: "../swagger.yaml#/definitions/error"
90
      "403":
91
        description: Access forbidden
92
        schema:
93
          $ref: "../swagger.yaml#/definitions/error"
94
      "404":
95
        description: Patron not found
96
        schema:
97
          $ref: "../swagger.yaml#/definitions/error"
98
      "500":
99
        description: |
100
          Internal server error. Possible `error_code` attribute values:
101
102
          * `internal_server_error`
103
        schema:
104
          $ref: "../swagger.yaml#/definitions/error"
105
      "503":
106
        description: Under maintenance
107
        schema:
108
          $ref: "../swagger.yaml#/definitions/error"
109
    x-koha-authorization:
110
      permissions:
111
        recalls: manage_recalls
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 489-494 paths: Link Here
489
    $ref: ./paths/quotes.yaml#/~1quotes
489
    $ref: ./paths/quotes.yaml#/~1quotes
490
  "/quotes/{quote_id}":
490
  "/quotes/{quote_id}":
491
    $ref: "./paths/quotes.yaml#/~1quotes~1{quote_id}"
491
    $ref: "./paths/quotes.yaml#/~1quotes~1{quote_id}"
492
  /recalls:
493
    $ref: ./paths/recalls.yaml#/~1recalls
492
  /return_claims:
494
  /return_claims:
493
    $ref: ./paths/return_claims.yaml#/~1return_claims
495
    $ref: ./paths/return_claims.yaml#/~1return_claims
494
  "/return_claims/{claim_id}":
496
  "/return_claims/{claim_id}":
(-)a/t/db_dependent/api/v1/recalls.t (-1 / +64 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/recalls")->status_is( 200, 'SWAGGER3.2.2' )->json_is( [] );
52
53
    my $recall_1 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } );
54
    my $recall_2 =
55
        $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id, completed => 1 } } );
56
57
    $t->get_ok( "//$userid:$password@/api/v1/recalls?patron_id=" . $patron->id )->status_is( 200, 'SWAGGER3.2.2' )
58
        ->json_is( '' => [ $recall_1->to_api, $recall_2->to_api ], 'Recalls for patron retrieved' );
59
60
    $t->get_ok( "//$userid:$password@/api/v1/recalls?completed=false" )
61
        ->status_is( 200, 'SWAGGER3.2.2' )->json_is( '' => [ $recall_1->to_api ], 'Current recalls retrieved' );
62
63
    $schema->storage->txn_rollback;
64
};

Return to bug 36075