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

(-)a/Koha/Desk.pm (-1 / +15 lines)
Lines 29-38 Koha::Desk - Koha Desk Object class Link Here
29
29
30
=head1 API
30
=head1 API
31
31
32
=head2 Class Methods
32
=head2 Class methods
33
34
=head3 to_api_mapping
35
36
This method returns the mapping for representing a Koha::Desk object
37
on the API.
33
38
34
=cut
39
=cut
35
40
41
sub to_api_mapping {
42
    return {
43
        branchcode => 'library_id',
44
        desk_name  => 'name',
45
    };
46
}
47
48
=head2 Internal methods
49
36
=head3 _type
50
=head3 _type
37
51
38
=cut
52
=cut
(-)a/Koha/REST/V1/Libraries.pm (+31 lines)
Lines 169-172 sub delete { Link Here
169
    };
169
    };
170
}
170
}
171
171
172
=head3 list_desks
173
174
Controller function that handles retrieving the library's desks
175
176
=cut
177
178
sub list_desks {
179
    my $c = shift->openapi->valid_input or return;
180
181
    return $c->render( status => 404, openapi => { error => "Feature disabled" } )
182
        unless C4::Context->preference('UseCirculationDesks');
183
184
    return try {
185
        my $library = Koha::Libraries->find( $c->param('library_id') );
186
187
        unless ($library) {
188
            return $c->render(
189
                status  => 404,
190
                openapi => { error => "Library not found" }
191
            );
192
        }
193
194
        return $c->render(
195
            status  => 200,
196
            openapi => $c->objects->to_api( $library->desks )
197
        );
198
    } catch {
199
        $c->unhandled_exception($_);
200
    };
201
}
202
172
1;
203
1;
(-)a/api/v1/swagger/definitions/desk.yaml (+19 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  desk_id:
5
    type: integer
6
    description: Internal desk identifier
7
  name:
8
    type: string
9
    description: The desk display name
10
  library_id:
11
    type: string
12
    description: Internally assigned library identifier
13
    maxLength: 10
14
    minLength: 1
15
additionalProperties: false
16
required:
17
  - desk_id
18
  - name
19
  - library_id
(-)a/api/v1/swagger/paths/libraries.yaml (+42 lines)
Lines 304-309 Link Here
304
    x-koha-authorization:
304
    x-koha-authorization:
305
      permissions:
305
      permissions:
306
        parameters: manage_libraries
306
        parameters: manage_libraries
307
"/libraries/{library_id}/desks":
308
  get:
309
    x-mojo-to: Libraries#list_desks
310
    operationId: listLibraryDesks
311
    tags:
312
      - desks
313
    summary: List the library's desks
314
    parameters:
315
      - $ref: "../swagger.yaml#/parameters/match"
316
      - $ref: "../swagger.yaml#/parameters/order_by"
317
      - $ref: "../swagger.yaml#/parameters/page"
318
      - $ref: "../swagger.yaml#/parameters/per_page"
319
      - $ref: "../swagger.yaml#/parameters/q_param"
320
      - $ref: "../swagger.yaml#/parameters/q_body"
321
      - $ref: "../swagger.yaml#/parameters/request_id_header"
322
    produces:
323
      - application/json
324
    responses:
325
      200:
326
        description: A list of desks for the library
327
        schema:
328
          type: array
329
          items:
330
            $ref: "../swagger.yaml#/definitions/desk"
331
      404:
332
        description: Resource not found
333
        schema:
334
          $ref: "../swagger.yaml#/definitions/error"
335
      500:
336
        description: |
337
          Internal server error. Possible `error_code` attribute values:
338
339
          * `internal_server_error`
340
        schema:
341
          $ref: "../swagger.yaml#/definitions/error"
342
      503:
343
        description: Under maintenance
344
        schema:
345
          $ref: "../swagger.yaml#/definitions/error"
346
    x-koha-authorization:
347
      permissions:
348
        catalogue: 1
307
/public/libraries:
349
/public/libraries:
308
  get:
350
  get:
309
    x-mojo-to: Libraries#list
351
    x-mojo-to: Libraries#list
(-)a/api/v1/swagger/swagger.yaml (+7 lines)
Lines 38-43 definitions: Link Here
38
    $ref: ./definitions/credit.yaml
38
    $ref: ./definitions/credit.yaml
39
  debit:
39
  debit:
40
    $ref: ./definitions/debit.yaml
40
    $ref: ./definitions/debit.yaml
41
  desk:
42
    $ref: ./definitions/desk.yaml
41
  edifact_file:
43
  edifact_file:
42
    $ref: ./definitions/edifact_file.yaml
44
    $ref: ./definitions/edifact_file.yaml
43
  erm_config:
45
  erm_config:
Lines 407-412 paths: Link Here
407
    $ref: ./paths/libraries.yaml#/~1libraries
409
    $ref: ./paths/libraries.yaml#/~1libraries
408
  "/libraries/{library_id}":
410
  "/libraries/{library_id}":
409
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}"
411
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}"
412
  "/libraries/{library_id}/desks":
413
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
410
  "/oauth/login/{provider_code}/{interface}":
414
  "/oauth/login/{provider_code}/{interface}":
411
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
415
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
412
  /oauth/token:
416
  /oauth/token:
Lines 1036-1041 tags: Link Here
1036
  - description: "Manage patron clubs\n"
1040
  - description: "Manage patron clubs\n"
1037
    name: clubs
1041
    name: clubs
1038
    x-displayName: Clubs
1042
    x-displayName: Clubs
1043
  - description: "Manage circulation desks\n"
1044
    name: desks
1045
    x-displayName: Circulation desks
1039
  - description: "Manage ERM agreements\n"
1046
  - description: "Manage ERM agreements\n"
1040
    name: erm_agreements
1047
    name: erm_agreements
1041
    x-displayName: ERM agreements
1048
    x-displayName: ERM agreements
(-)a/t/db_dependent/api/v1/libraries.t (-2 / +42 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
use Test::Mojo;
21
use Test::Mojo;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 315-317 subtest 'delete() tests' => sub { Link Here
315
315
316
    $schema->storage->txn_rollback;
316
    $schema->storage->txn_rollback;
317
};
317
};
318
- 
318
319
subtest 'list_desks() tests' => sub {
320
321
    plan tests => 11;
322
323
    $schema->storage->txn_begin;
324
325
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
326
    my $patron  = $builder->build_object(
327
        {
328
            class => 'Koha::Patrons',
329
            value => { flags => 4 }
330
        }
331
    );
332
    my $password = 'thePassword123';
333
    $patron->set_password( { password => $password, skip_validation => 1 } );
334
    my $userid = $patron->userid;
335
336
    t::lib::Mocks::mock_preference( 'UseCirculationDesks', 0 );
337
338
    $t->get_ok( "//$userid:$password@/api/v1/libraries/" . $library->branchcode . "/desks" )->status_is(404)
339
        ->json_is( '/error' => q{Feature disabled} );
340
341
    my $non_existent_code = $library->branchcode;
342
    $library->delete;
343
344
    t::lib::Mocks::mock_preference( 'UseCirculationDesks', 1 );
345
346
    $t->get_ok( "//$userid:$password@/api/v1/libraries/" . $non_existent_code . "/desks" )->status_is(404)
347
        ->json_is( '/error' => 'Library not found' );
348
349
    my $desk_1 = $builder->build_object( { class => 'Koha::Desks', value => { branchcode => $library->id } } );
350
    my $desk_2 = $builder->build_object( { class => 'Koha::Desks', value => { branchcode => $library->id } } );
351
352
    my $res = $t->get_ok( "//$userid:$password@/api/v1/libraries/" . $library->branchcode . "/desks" )->status_is(200)
353
        ->json_is( '/0/desk_id' => $desk_1->id )->json_is( '/1/desk_id' => $desk_2->id )->tx->res->json;
354
355
    is( scalar @{$res}, 2 );
356
357
    $schema->storage->txn_rollback;
358
};

Return to bug 36480