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

(-)a/api/v1/swagger/definitions/erm_counts.yaml (-7 lines)
Lines 1-7 Link Here
1
---
2
type: object
3
properties:
4
  counts:
5
    type: object
6
    description: List of ERM resources counts
7
additionalProperties: false
(-)a/api/v1/swagger/paths/erm_counts.yaml (-38 lines)
Lines 1-38 Link Here
1
---
2
/erm/counts:
3
  get:
4
    x-mojo-to: ERM#counts
5
    operationId: getERMcounts
6
    description: This resource returns a list of ERM resources counts
7
    summary: get the ERM counts
8
    tags:
9
      - erm_counts
10
    produces:
11
      - application/json
12
    responses:
13
      200:
14
        description: The ERM counts
15
        schema:
16
          $ref: "../swagger.yaml#/definitions/erm_counts"
17
      400:
18
        description: Bad request
19
        schema:
20
          $ref: "../swagger.yaml#/definitions/error"
21
      403:
22
        description: Access forbidden
23
        schema:
24
          $ref: "../swagger.yaml#/definitions/error"
25
      500:
26
        description: |
27
          Internal server error. Possible `error_code` attribute values:
28
29
          * `internal_server_error`
30
        schema:
31
          $ref: "../swagger.yaml#/definitions/error"
32
      503:
33
        description: Under maintenance
34
        schema:
35
          $ref: "../swagger.yaml#/definitions/error"
36
    x-koha-authorization:
37
      permissions:
38
        erm: 1
(-)a/api/v1/swagger/swagger.yaml (-7 lines)
Lines 50-57 definitions: Link Here
50
    $ref: ./definitions/desk.yaml
50
    $ref: ./definitions/desk.yaml
51
  edifact_file:
51
  edifact_file:
52
    $ref: ./definitions/edifact_file.yaml
52
    $ref: ./definitions/edifact_file.yaml
53
  erm_counts:
54
    $ref: ./definitions/erm_counts.yaml
55
  erm_config:
53
  erm_config:
56
    $ref: ./definitions/erm_config.yaml
54
    $ref: ./definitions/erm_config.yaml
57
  erm_agreement:
55
  erm_agreement:
Lines 337-344 paths: Link Here
337
    $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios~1{biblio_id}"
335
    $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios~1{biblio_id}"
338
  /erm/config:
336
  /erm/config:
339
    $ref: ./paths/erm_config.yaml#/~1erm~1config
337
    $ref: ./paths/erm_config.yaml#/~1erm~1config
340
  /erm/counts:
341
    $ref: ./paths/erm_counts.yaml#/~1erm~1counts
342
  /erm/agreements:
338
  /erm/agreements:
343
    $ref: ./paths/erm_agreements.yaml#/~1erm~1agreements
339
    $ref: ./paths/erm_agreements.yaml#/~1erm~1agreements
344
  "/erm/agreements/{agreement_id}":
340
  "/erm/agreements/{agreement_id}":
Lines 1208-1216 tags: Link Here
1208
  - description: "Manage ERM configuration\n"
1204
  - description: "Manage ERM configuration\n"
1209
    name: erm_config
1205
    name: erm_config
1210
    x-displayName: ERM configuration
1206
    x-displayName: ERM configuration
1211
  - description: "Get ERM resources counts\n"
1212
    name: erm_counts
1213
    x-displayName: ERM counts
1214
  - description: "Manage ERM counter files\n"
1207
  - description: "Manage ERM counter files\n"
1215
    name: erm_counter_files
1208
    name: erm_counter_files
1216
    x-displayName: ERM counter files
1209
    x-displayName: ERM counter files
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/erm-api-client.js (-9 lines)
Lines 447-461 export class ERMAPIClient { Link Here
447
                }),
447
                }),
448
        };
448
        };
449
    }
449
    }
450
451
    get counts() {
452
        return {
453
            get: () =>
454
                this.httpClient.get({
455
                    endpoint: "counts",
456
                }),
457
        };
458
    }
459
}
450
}
460
451
461
export default ERMAPIClient;
452
export default ERMAPIClient;
(-)a/t/db_dependent/api/v1/erm_counts.t (-92 lines)
Lines 1-91 Link Here
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 <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::NoWarnings;
21
use Test::More tests => 2;
22
use Test::Mojo;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
use Koha::ERM::Agreements;
28
use Koha::ERM::Documents;
29
use Koha::ERM::EHoldings::Packages;
30
use Koha::ERM::EHoldings::Titles;
31
use Koha::ERM::Licenses;
32
use Koha::ERM::EUsage::UsageDataProviders;
33
34
use Koha::Database;
35
36
my $schema  = Koha::Database->new->schema;
37
my $builder = t::lib::TestBuilder->new;
38
39
my $t = Test::Mojo->new('Koha::REST::V1');
40
41
subtest 'count() tests' => sub {
42
43
    plan tests => 3;
44
45
    $schema->storage->txn_begin;
46
47
    Koha::ERM::Agreements->search->delete;
48
    Koha::ERM::Documents->search->delete;
49
    Koha::ERM::EHoldings::Packages->search->delete;
50
    Koha::ERM::EHoldings::Titles->search->delete;
51
    Koha::ERM::Licenses->search->delete;
52
    Koha::ERM::EUsage::UsageDataProviders->search->delete;
53
54
    my $librarian = $builder->build_object(
55
        {
56
            class => 'Koha::Patrons',
57
            value => { flags => 2**28 }
58
        }
59
    );
60
61
    my $password = 'thePassword123';
62
    $librarian->set_password( { password => $password, skip_validation => 1 } );
63
    my $userid = $librarian->userid;
64
65
    ## Authorized user tests
66
    my $agreement = $builder->build_object(
67
        {
68
            class => 'Koha::ERM::Agreements',
69
        }
70
    );
71
72
    my $license = $builder->build_object(
73
        {
74
            class => 'Koha::ERM::Licenses',
75
        }
76
    );
77
78
    $t->get_ok("//$userid:$password@/api/v1/erm/counts")->status_is(200)->json_is(
79
        {
80
            counts => {
81
                agreements_count           => 1,
82
                documents_count            => 0,
83
                eholdings_packages_count   => 0,
84
                eholdings_titles_count     => 0,
85
                licenses_count             => 1,
86
                usage_data_providers_count => 0
87
            }
88
        }
89
    );
90
    $schema->storage->txn_rollback;
91
};
92
- 

Return to bug 39320