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

(-)a/Koha/Cash/Register.pm (+14 lines)
Lines 233-238 sub add_cashup { Link Here
233
    return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
233
    return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
234
}
234
}
235
235
236
=head3 to_api_mapping
237
238
This method returns the mapping for representing a Koha::Cash::Register object
239
on the API.
240
241
=cut
242
243
sub to_api_mapping {
244
    return {
245
        branch => 'library_id',
246
        id     => 'cash_register_id',
247
    };
248
}
249
236
=head2 Internal methods
250
=head2 Internal methods
237
251
238
=cut
252
=cut
(-)a/Koha/REST/V1/Libraries.pm (+31 lines)
Lines 200-203 sub list_desks { Link Here
200
    };
200
    };
201
}
201
}
202
202
203
=head3 list_cash_registers
204
205
Controller function that handles retrieving the library's cash registers
206
207
=cut
208
209
sub list_cash_registers {
210
    my $c = shift->openapi->valid_input or return;
211
212
    return $c->render( status => 404, openapi => { error => "Feature disabled" } )
213
        unless C4::Context->preference('UseCashRegisters');
214
215
    return try {
216
        my $library = Koha::Libraries->find( $c->param('library_id') );
217
218
        unless ($library) {
219
            return $c->render(
220
                status  => 404,
221
                openapi => { error => "Library not found" }
222
            );
223
        }
224
225
        return $c->render(
226
            status  => 200,
227
            openapi => $c->objects->to_api( $library->cash_registers )
228
        );
229
    } catch {
230
        $c->unhandled_exception($_);
231
    };
232
}
233
203
1;
234
1;
(-)a/api/v1/swagger/definitions/cash_register.yaml (+33 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  cash_register_id:
5
    type: integer
6
    description: Internal cash register identifier
7
  name:
8
    type: string
9
    description: The cash register display name
10
  library_id:
11
    type: string
12
    description: Internally assigned library identifier
13
    maxLength: 10
14
    minLength: 1
15
  description:
16
    type: string
17
    description: A description
18
  starting_float:
19
    type:
20
      - number
21
      - "null"
22
    description: The starting float this account register should be assigned
23
  archived:
24
    type: boolean
25
    description: If this till is archived
26
  branch_default:
27
    type: boolean
28
    description: If this till is the branch default
29
additionalProperties: false
30
required:
31
  - cash_register_id
32
  - name
33
  - library_id
(-)a/api/v1/swagger/paths/libraries.yaml (+42 lines)
Lines 346-351 Link Here
346
    x-koha-authorization:
346
    x-koha-authorization:
347
      permissions:
347
      permissions:
348
        catalogue: 1
348
        catalogue: 1
349
"/libraries/{library_id}/cash_registers":
350
  get:
351
    x-mojo-to: Libraries#list_cash_registers
352
    operationId: listLibraryCashRegisters
353
    tags:
354
      - cash_registers
355
    summary: List the library's cash registers
356
    parameters:
357
      - $ref: "../swagger.yaml#/parameters/match"
358
      - $ref: "../swagger.yaml#/parameters/order_by"
359
      - $ref: "../swagger.yaml#/parameters/page"
360
      - $ref: "../swagger.yaml#/parameters/per_page"
361
      - $ref: "../swagger.yaml#/parameters/q_param"
362
      - $ref: "../swagger.yaml#/parameters/q_body"
363
      - $ref: "../swagger.yaml#/parameters/request_id_header"
364
    produces:
365
      - application/json
366
    responses:
367
      200:
368
        description: A list of desks for the library
369
        schema:
370
          type: array
371
          items:
372
            $ref: "../swagger.yaml#/definitions/cash_register"
373
      404:
374
        description: Resource not found
375
        schema:
376
          $ref: "../swagger.yaml#/definitions/error"
377
      500:
378
        description: |
379
          Internal server error. Possible `error_code` attribute values:
380
381
          * `internal_server_error`
382
        schema:
383
          $ref: "../swagger.yaml#/definitions/error"
384
      503:
385
        description: Under maintenance
386
        schema:
387
          $ref: "../swagger.yaml#/definitions/error"
388
    x-koha-authorization:
389
      permissions:
390
        catalogue: 1
349
/public/libraries:
391
/public/libraries:
350
  get:
392
  get:
351
    x-mojo-to: Libraries#list
393
    x-mojo-to: Libraries#list
(-)a/api/v1/swagger/swagger.yaml (+7 lines)
Lines 22-27 definitions: Link Here
22
    $ref: ./definitions/booking.yaml
22
    $ref: ./definitions/booking.yaml
23
  bundle_link:
23
  bundle_link:
24
    $ref: ./definitions/bundle_link.yaml
24
    $ref: ./definitions/bundle_link.yaml
25
  cash_register:
26
    $ref: ./definitions/cash_register.yaml
25
  cashup:
27
  cashup:
26
    $ref: ./definitions/cashup.yaml
28
    $ref: ./definitions/cashup.yaml
27
  checkout:
29
  checkout:
Lines 409-414 paths: Link Here
409
    $ref: ./paths/libraries.yaml#/~1libraries
411
    $ref: ./paths/libraries.yaml#/~1libraries
410
  "/libraries/{library_id}":
412
  "/libraries/{library_id}":
411
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}"
413
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}"
414
  "/libraries/{library_id}/cash_registers":
415
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1cash_registers"
412
  "/libraries/{library_id}/desks":
416
  "/libraries/{library_id}/desks":
413
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
417
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
414
  "/oauth/login/{provider_code}/{interface}":
418
  "/oauth/login/{provider_code}/{interface}":
Lines 1025-1030 tags: Link Here
1025
  - description: "Manage bibliographic records\n"
1029
  - description: "Manage bibliographic records\n"
1026
    name: biblios
1030
    name: biblios
1027
    x-displayName: Biblios
1031
    x-displayName: Biblios
1032
  - description: "Manage cash registers\n"
1033
    name: cash_registers
1034
    x-displayName: Cash registers
1028
  - description: "Manage cash register cashups\n"
1035
  - description: "Manage cash register cashups\n"
1029
    name: cashups
1036
    name: cashups
1030
    x-displayName: Cashups
1037
    x-displayName: Cashups
(-)a/t/db_dependent/api/v1/libraries.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 => 6;
20
use Test::More tests => 7;
21
use Test::Mojo;
21
use Test::Mojo;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 356-358 subtest 'list_desks() tests' => sub { Link Here
356
356
357
    $schema->storage->txn_rollback;
357
    $schema->storage->txn_rollback;
358
};
358
};
359
- 
359
360
subtest 'list_cash_registers() tests' => sub {
361
362
    plan tests => 11;
363
364
    $schema->storage->txn_begin;
365
366
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
367
    my $patron  = $builder->build_object(
368
        {
369
            class => 'Koha::Patrons',
370
            value => { flags => 4 }
371
        }
372
    );
373
    my $password = 'thePassword123';
374
    $patron->set_password( { password => $password, skip_validation => 1 } );
375
    my $userid = $patron->userid;
376
377
    t::lib::Mocks::mock_preference( 'UseCashRegisters', 0 );
378
379
    $t->get_ok( "//$userid:$password@/api/v1/libraries/" . $library->branchcode . "/cash_registers" )->status_is(404)
380
        ->json_is( '/error' => q{Feature disabled} );
381
382
    my $non_existent_code = $library->branchcode;
383
    $library->delete;
384
385
    t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 );
386
387
    $t->get_ok( "//$userid:$password@/api/v1/libraries/" . $non_existent_code . "/cash_registers" )->status_is(404)
388
        ->json_is( '/error' => 'Library not found' );
389
390
    my $cash_register_1 =
391
        $builder->build_object( { class => 'Koha::Cash::Registers', value => { branch => $library->id } } );
392
    my $cash_register_2 =
393
        $builder->build_object( { class => 'Koha::Cash::Registers', value => { branch => $library->id } } );
394
395
    my $res =
396
        $t->get_ok( "//$userid:$password@/api/v1/libraries/" . $library->branchcode . "/cash_registers" )
397
        ->status_is(200)->json_is( '/0/cash_register_id' => $cash_register_1->id )
398
        ->json_is( '/1/cash_register_id' => $cash_register_2->id )->tx->res->json;
399
400
    is( scalar @{$res}, 2 );
401
402
    $schema->storage->txn_rollback;
403
};

Return to bug 36481