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

(-)a/Koha/Illrequest.pm (+96 lines)
Lines 24-29 use Try::Tiny qw( catch try ); Link Here
24
use DateTime;
24
use DateTime;
25
25
26
use C4::Letters;
26
use C4::Letters;
27
28
use Koha::Cache::Memory::Lite;
27
use Koha::Database;
29
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
30
use Koha::DateUtils qw( dt_from_string );
29
use Koha::Exceptions::Ill;
31
use Koha::Exceptions::Ill;
Lines 1879-1884 sub TO_JSON { Link Here
1879
1881
1880
=head2 Internal methods
1882
=head2 Internal methods
1881
1883
1884
=head3 to_api_mapping
1885
1886
=cut
1887
1888
sub to_api_mapping {
1889
    return {
1890
        illrequest_id  => 'ill_request_id',
1891
        borrowernumber => 'patron_id',
1892
        branchcode     => 'library_id',
1893
        status_alias   => 'status_av',
1894
        placed         => 'requested_date',
1895
        replied        => 'replied_date',
1896
        updated        => 'timestamp',
1897
        completed      => 'completed_date',
1898
        accessurl      => 'access_url',
1899
        price_paid     => 'paid_price',
1900
        notesopac      => 'opac_notes',
1901
        notesstaff     => 'staff_notes',
1902
        orderid        => 'ill_backend_request_id',
1903
        backend        => 'ill_backend_id',
1904
    };
1905
}
1906
1907
=head3 strings_map
1908
1909
    my $strings = $self->string_map({ [ public => 0|1 ] });
1910
1911
Returns a map of column name to string representations. Extra information
1912
is returned depending on the column characteristics as shown below.
1913
1914
Accepts a param hashref where the I<public> key denotes whether we want the public
1915
or staff client strings.
1916
1917
Example:
1918
1919
    {
1920
        status => {
1921
            backend => 'backendName',
1922
            str     => 'Status description',
1923
            type    => 'ill_status',
1924
        },
1925
        status_alias => {
1926
            category => 'ILL_STATUS_ALIAS,
1927
            str      => $value, # the AV description, depending on $params->{public}
1928
            type     => 'av',
1929
        }
1930
    }
1931
1932
=cut
1933
1934
sub strings_map {
1935
    my ( $self, $params ) = @_;
1936
1937
    my $cache     = Koha::Cache::Memory::Lite->get_instance();
1938
    my $cache_key = 'ill:status_graph:' . $self->backend;
1939
1940
    my $status_graph_union = $cache->get($cache_key);
1941
    unless ($status_graph_union) {
1942
        $status_graph_union = $self->capabilities;
1943
        $cache->set( $cache_key, $status_graph_union );
1944
    }
1945
1946
    my $status_string =
1947
      ( exists $status_graph_union->{ $self->status } && defined $status_graph_union->{ $self->status }->{name} )
1948
      ? $status_graph_union->{ $self->status }->{name}
1949
      : $self->status;
1950
1951
    my $status_code =
1952
      ( exists $status_graph_union->{ $self->status } && defined $status_graph_union->{ $self->status }->{id} )
1953
      ? $status_graph_union->{ $self->status }->{id}
1954
      : $self->status;
1955
1956
    my $strings = {
1957
        status => {
1958
            backend => $self->backend, # the backend identifier
1959
            str     => $status_string, # the status description, taken from the status graph
1960
            code    => $status_code,   # the status id, taken from the status graph
1961
            type    => 'ill_status',   # fixed type
1962
        }
1963
    };
1964
1965
    my $status_alias = $self->statusalias;
1966
    if ($status_alias) {
1967
        $strings->{"status_alias"} = {
1968
            category => 'ILL_STATUS_ALIAS',
1969
            str      => $params->{public} ? $status_alias->lib_opac : $status_alias->lib,
1970
            code     => $status_alias->authorised_value,
1971
            type     => 'av',
1972
        };
1973
    }
1974
1975
    return $strings;
1976
}
1977
1882
=head3 _type
1978
=head3 _type
1883
1979
1884
=cut
1980
=cut
(-)a/api/v1/swagger/definitions/ill_request.yaml (+137 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  ill_request_id:
5
    type: integer
6
    description: Internal ILL request identifier
7
  biblio_id:
8
    type:
9
      - integer
10
      - "null"
11
    description: Internal bibliographic record identifier
12
  patron_id:
13
    type:
14
      - integer
15
      - "null"
16
    description: Internal patron id
17
  due_date:
18
    type:
19
      - string
20
      - "null"
21
    format: date-time
22
    description: Date and time the request item should be due when checked out
23
  library_id:
24
    type: string
25
    description: Internal library identifier
26
  requested_date:
27
    type: string
28
    format: date
29
    description: Date the request was placed by the patron
30
  replied_date:
31
    type:
32
      - string
33
      - "null"
34
    format: date
35
    description: FIXME
36
  timestamp:
37
    type: string
38
    format: date-time
39
    description: Date and time of last object update
40
  completed_date:
41
    type:
42
      - string
43
      - "null"
44
    format: date
45
    description: Date the request was marked as completed
46
  access_url:
47
    type:
48
      - string
49
      - "null"
50
    description: A URL for accessing the item
51
  status:
52
    type: string
53
    description: |
54
      The status the request is at.
55
56
      Note: This is defined by each backend. Please refer to the specific backend's
57
      documentation or code to understand the possible values.
58
  medium:
59
    type:
60
      - string
61
      - "null"
62
    description: Description of the ILL item medium
63
  cost:
64
    type:
65
      - string
66
      - "null"
67
    description: Default request cost
68
  paid_price:
69
    type:
70
      - string
71
      - "null"
72
    description: Effective request cost
73
  opac_notes:
74
    type:
75
      - string
76
      - "null"
77
    description: Note that is visible to the patron
78
  staff_notes:
79
    type:
80
      - string
81
      - "null"
82
    description: Interal staff note about the request
83
  ill_backend_id:
84
    type: string
85
    description: The ILL backend identifier string
86
  ill_backend_request_id:
87
    type:
88
      - string
89
      - "null"
90
    description: Backend-specific request id
91
  status_av:
92
    type:
93
      - string
94
      - "null"
95
    description: The authorised value category the field is linked to
96
  biblio:
97
    type:
98
      - object
99
      - "null"
100
    description: The linked biblio object (x-koha-embed)
101
  comments:
102
    type:
103
      - array
104
      - "null"
105
    description: The linked comment objects (x-koha-embed)
106
  comments_count:
107
    type:
108
      - integer
109
      - "null"
110
    description: The linked comment objects count (x-koha-embed)
111
  ill_extended_attributes:
112
    type:
113
      - array
114
      - "null"
115
    description: The linked extended ill request attributes (x-koha-embed)
116
  library:
117
    type:
118
      - object
119
      - "null"
120
    description: The linked library object (x-koha-embed)
121
  id_prefix:
122
    type:
123
      - string
124
      - "null"
125
    description: The id_prefix of the request (x-koha-embed)
126
  patron:
127
    type:
128
      - object
129
      - "null"
130
    description: The linked patron object (x-koha-embed)
131
  _strings:
132
    type:
133
      - object
134
      - "null"
135
    description: Expanded coded fiels (x-koha-embed)
136
137
additionalProperties: false
(-)a/api/v1/swagger/paths/illrequests.yaml (-92 / +26 lines)
Lines 1-118 Link Here
1
---
1
---
2
/illrequests:
2
/ill_requests:
3
  get:
3
  get:
4
    x-mojo-to: Illrequests#list
4
    x-mojo-to: Illrequests#list
5
    operationId: listIllrequests
5
    operationId: listIllrequests
6
    tags:
6
    tags:
7
      - illrequests
7
      - ill_requests
8
    summary: List ILL requests
8
    summary: List ILL requests
9
    parameters:
9
    parameters:
10
      - name: embed
10
      - $ref: "../swagger.yaml#/parameters/page"
11
        in: query
11
      - $ref: "../swagger.yaml#/parameters/per_page"
12
        description: Additional objects that should be embedded in the response
12
      - $ref: "../swagger.yaml#/parameters/match"
13
        required: false
13
      - $ref: "../swagger.yaml#/parameters/order_by"
14
      - $ref: "../swagger.yaml#/parameters/q_param"
15
      - $ref: "../swagger.yaml#/parameters/q_body"
16
      - $ref: "../swagger.yaml#/parameters/q_header"
17
      - $ref: "../swagger.yaml#/parameters/request_id_header"
18
      - name: x-koha-embed
19
        in: header
20
        required: false
21
        description: Embed list sent as a request header
14
        type: array
22
        type: array
15
        collectionFormat: csv
16
        items:
23
        items:
17
          type: string
24
          type: string
18
          enum:
25
          enum:
19
            - patron
26
            - +strings
20
            - library
27
            - biblio
21
            - capabilities
22
            - metadata
23
            - requested_partners
24
            - comments
28
            - comments
25
            - status_alias
29
            - comments+count
26
      - name: backend
30
            - ill_extended_attributes
27
        in: query
31
            - library
28
        description: The name of a ILL backend
32
            - id_prefix
29
        required: false
33
            - patron
30
        type: string
34
        collectionFormat: csv
31
      - name: orderid
32
        in: query
33
        description: The order ID of a request
34
        required: false
35
        type: string
36
      - name: biblionumber
37
        in: query
38
        description: Internal biblio identifier
39
        required: false
40
        type: integer
41
      - name: borrowernumber
42
        in: query
43
        description: Internal patron identifier
44
        required: false
45
        type: integer
46
      - name: completed
47
        in: query
48
        description: The date the request was considered completed
49
        required: false
50
        type: string
51
      - name: completed_formatted
52
        in: query
53
        description: The date the request was considered complete formatted
54
        required: false
55
        type: string
56
      - name: status
57
        in: query
58
        description: A full status string e.g. REQREV
59
        required: false
60
        type: string
61
      - name: cost
62
        in: query
63
        description: The quoted cost of the request
64
        required: false
65
        type: number
66
      - name: price_paid
67
        in: query
68
        description: The final cost of the request
69
        required: false
70
        type: number
71
      - name: medium
72
        in: query
73
        description: The medium of the requested item
74
        required: false
75
        type: string
76
      - name: updated
77
        in: query
78
        description: The last updated date of the request
79
        required: false
80
        type: string
81
      - name: updated_formatted
82
        in: query
83
        description: The last updated date of the request formatted
84
        required: false
85
        type: string
86
      - name: placed
87
        in: query
88
        description: The date the request was placed
89
        required: false
90
        type: string
91
      - name: placed_formatted
92
        in: query
93
        description: The date the request was placed formatted
94
        required: false
95
        type: string
96
      - name: branchcode
97
        in: query
98
        description: Library ID
99
        required: false
100
        type: string
101
    produces:
35
    produces:
102
      - application/json
36
      - application/json
103
    responses:
37
    responses:
104
      "200":
38
      "200":
105
        description: A list of ILL requests
39
        description: A list of ILL requests
106
      "401":
107
        description: Authentication required
108
        schema:
40
        schema:
109
          $ref: "../swagger.yaml#/definitions/error"
41
          type: array
42
          items:
43
            $ref: "../swagger.yaml#/definitions/ill_request"
110
      "403":
44
      "403":
111
        description: Access forbidden
45
        description: Access forbidden
112
        schema:
46
        schema:
113
          $ref: "../swagger.yaml#/definitions/error"
47
          $ref: "../swagger.yaml#/definitions/error"
114
      "404":
48
      "404":
115
        description: ILL requests not found
49
        description: Patron not found
116
        schema:
50
        schema:
117
          $ref: "../swagger.yaml#/definitions/error"
51
          $ref: "../swagger.yaml#/definitions/error"
118
      "500":
52
      "500":
(-)a/api/v1/swagger/swagger.yaml (+4 lines)
Lines 52-57 definitions: Link Here
52
    $ref: ./definitions/ill_backend.yaml
52
    $ref: ./definitions/ill_backend.yaml
53
  ill_backends:
53
  ill_backends:
54
    $ref: ./definitions/ill_backends.yaml
54
    $ref: ./definitions/ill_backends.yaml
55
  ill_request:
56
    $ref: ./definitions/ill_request.yaml
55
  import_batch_profile:
57
  import_batch_profile:
56
    $ref: ./definitions/import_batch_profile.yaml
58
    $ref: ./definitions/import_batch_profile.yaml
57
  import_batch_profiles:
59
  import_batch_profiles:
Lines 245-250 paths: Link Here
245
    $ref: "./paths/ill_backends.yaml#/~1ill_backends~1{ill_backend_id}"
247
    $ref: "./paths/ill_backends.yaml#/~1ill_backends~1{ill_backend_id}"
246
  /illrequests:
248
  /illrequests:
247
    $ref: ./paths/illrequests.yaml#/~1illrequests
249
    $ref: ./paths/illrequests.yaml#/~1illrequests
250
  /ill_requests:
251
    $ref: ./paths/illrequests.yaml#/~1ill_requests
248
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
252
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
249
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
253
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
250
  /import_batch_profiles:
254
  /import_batch_profiles:
(-)a/t/db_dependent/api/v1/illrequests.t (-3 / +56 lines)
Lines 17-28 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 2;
21
21
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::MockObject;
23
use Test::MockObject;
24
use Test::Mojo;
24
use Test::Mojo;
25
25
26
use JSON qw(encode_json);
27
26
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
27
use t::lib::Mocks;
29
use t::lib::Mocks;
28
30
Lines 36-42 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); Link Here
36
38
37
my $t = Test::Mojo->new('Koha::REST::V1');
39
my $t = Test::Mojo->new('Koha::REST::V1');
38
40
39
subtest 'list() tests' => sub {
41
subtest 'list_legacy() tests' => sub {
40
42
41
    plan tests => 30;
43
    plan tests => 30;
42
44
Lines 94-99 subtest 'list() tests' => sub { Link Here
94
            class => 'Koha::Illrequests',
96
            class => 'Koha::Illrequests',
95
            value => {
97
            value => {
96
                backend        => 'Mock',
98
                backend        => 'Mock',
99
                biblio_id      => undef,
97
                branchcode     => $library->branchcode,
100
                branchcode     => $library->branchcode,
98
                borrowernumber => $patron_1->borrowernumber,
101
                borrowernumber => $patron_1->borrowernumber,
99
                status         => 'STATUS1',
102
                status         => 'STATUS1',
Lines 129-134 subtest 'list() tests' => sub { Link Here
129
            class => 'Koha::Illrequests',
132
            class => 'Koha::Illrequests',
130
            value => {
133
            value => {
131
                backend        => 'Mock',
134
                backend        => 'Mock',
135
                biblio_id      => undef,
132
                branchcode     => $library->branchcode,
136
                branchcode     => $library->branchcode,
133
                borrowernumber => $patron_2->borrowernumber,
137
                borrowernumber => $patron_2->borrowernumber,
134
                status         => 'STATUS2',
138
                status         => 'STATUS2',
Lines 173-178 subtest 'list() tests' => sub { Link Here
173
    $schema->storage->txn_rollback;
177
    $schema->storage->txn_rollback;
174
};
178
};
175
179
180
subtest 'list() tests' => sub {
181
182
    plan tests => 9;
183
184
    $schema->storage->txn_begin;
185
186
    Koha::Illrequests->search->delete;
187
188
    my $librarian = $builder->build_object(
189
        {
190
            class => 'Koha::Patrons',
191
            value => { flags => 2 ** 22 } # 22 => ill
192
        }
193
    );
194
    my $password = 'thePassword123';
195
    $librarian->set_password( { password => $password, skip_validation => 1 } );
196
    my $userid = $librarian->userid;
197
198
    my $patron = $builder->build_object(
199
        {
200
            class => 'Koha::Patrons',
201
            value => { flags => 0 }
202
        }
203
    );
204
205
    $patron->set_password( { password => $password, skip_validation => 1 } );
206
    my $unauth_userid = $patron->userid;
207
208
    $t->get_ok("//$userid:$password@/api/v1/ill_requests")
209
      ->status_is(200)
210
      ->json_is( [] );
211
212
    my $req_1 = $builder->build_object({ class => 'Koha::Illrequests', value => { biblio_id => undef, status => 'REQ' } });
213
    my $req_2 = $builder->build_object({ class => 'Koha::Illrequests', value => { biblio_id => undef, status => 'REQ' } } );
214
    my $ret   = $builder->build_object({ class => 'Koha::Illrequests', value => { biblio_id => undef, status => 'RET' } } );
215
216
    $t->get_ok("//$userid:$password@/api/v1/ill_requests")
217
      ->status_is(200)
218
      ->json_is( [ $req_1->to_api, $req_2->to_api, $ret->to_api ]);
219
220
    my $query = encode_json({ status => 'REQ' });
221
222
    # Filtering works
223
    $t->get_ok("//$userid:$password@/api/v1/ill_requests?q=$query" )
224
      ->status_is(200)
225
      ->json_is( [ $req_1->to_api, $req_2->to_api ]);
226
227
    $schema->storage->txn_rollback;
228
};
229
176
sub add_formatted {
230
sub add_formatted {
177
    my $req = shift;
231
    my $req = shift;
178
    my @format_dates = ( 'placed', 'updated', 'completed' );
232
    my @format_dates = ( 'placed', 'updated', 'completed' );
179
- 

Return to bug 22440