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

(-)a/Koha/REST/V1/CirculationRules.pm (-2 / +69 lines)
Lines 21-27 use Mojo::Base 'Mojolicious::Controller'; Link Here
21
21
22
use Koha::CirculationRules;
22
use Koha::CirculationRules;
23
23
24
25
=head1 API
24
=head1 API
26
25
27
=head2 Methods
26
=head2 Methods
Lines 36-44 sub get_kinds { Link Here
36
    my $c = shift->openapi->valid_input or return;
35
    my $c = shift->openapi->valid_input or return;
37
36
38
    return $c->render(
37
    return $c->render(
39
        status => 200,
38
        status  => 200,
40
        openapi => Koha::CirculationRules->rule_kinds,
39
        openapi => Koha::CirculationRules->rule_kinds,
41
    );
40
    );
42
}
41
}
43
42
43
=head3 list_effective_rules
44
45
List all effective rules for the requested patron/item/branch combination
46
47
=cut
48
49
sub list_effective_rules {
50
    my $c = shift->openapi->valid_input or return;
51
52
    my $item_type       = $c->param('itemtype');
53
    my $branchcode      = $c->param('library');
54
    my $patron_category = $c->param('category');
55
    my $rules           = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ];
56
57
    if ($item_type) {
58
        my $type = Koha::ItemTypes->find($item_type);
59
        return $c->render_invalid_parameter_value(
60
            {
61
                path   => '/query/item_type',
62
                values => {
63
                    uri   => '/api/v1/item_types',
64
                    field => 'item_type_id'
65
                }
66
            }
67
        ) unless $type;
68
    }
69
70
    if ($branchcode) {
71
        my $library = Koha::Libraries->find($branchcode);
72
        return $c->render_invalid_parameter_value(
73
            {
74
                path   => '/query/library',
75
                values => {
76
                    uri   => '/api/v1/libraries',
77
                    field => 'library_id'
78
                }
79
            }
80
        ) unless $library;
81
    }
82
83
    if ($patron_category) {
84
        my $category = Koha::Patron::Categories->find($patron_category);
85
        return $c->render_invalid_parameter_value(
86
            {
87
                path   => '/query/patron_category',
88
                values => {
89
                    uri   => '/api/v1/patron_categories',
90
                    field => 'patron_category_id'
91
                }
92
            }
93
        ) unless $category;
94
    }
95
96
    my $effective_rules = Koha::CirculationRules->get_effective_rules(
97
        {
98
            categorycode => $patron_category,
99
            itemtype     => $item_type,
100
            branchcode   => $branchcode,
101
            rules        => $rules
102
        }
103
    );
104
105
    return $c->render(
106
        status  => 200,
107
        openapi => $effective_rules ? $effective_rules : {}
108
    );
109
}
110
44
1;
111
1;
(-)a/api/v1/swagger/definitions/circ-rule-kind.yaml (-1 / +1 lines)
Lines 10-15 properties: Link Here
10
        - branchcode
10
        - branchcode
11
        - categorycode
11
        - categorycode
12
        - itemtype
12
        - itemtype
13
additionalProperties: false
13
additionalProperties: true
14
required:
14
required:
15
  - scope
15
  - scope
(-)a/api/v1/swagger/paths/circulation-rules.yaml (-32 lines)
Lines 1-32 Link Here
1
---
2
/circulation-rules/kinds:
3
  get:
4
    x-mojo-to: CirculationRules#get_kinds
5
    operationId: getCirculationRuleKinds
6
    tags:
7
      - circulation_rules
8
    summary: Get circulation rules kinds
9
    produces:
10
      - application/json
11
    responses:
12
      "200":
13
        description: A map of rule kind information
14
        schema:
15
          type: object
16
          additionalProperties:
17
            $ref: "../swagger.yaml#/definitions/circ-rule-kind"
18
      "403":
19
        description: Access forbidden
20
        schema:
21
          $ref: "../swagger.yaml#/definitions/error"
22
      "500":
23
        description: |
24
          Internal server error. Possible `error_code` attribute values:
25
26
          * `internal_server_error`
27
        schema:
28
          $ref: "../swagger.yaml#/definitions/error"
29
      "503":
30
        description: Under maintenance
31
        schema:
32
          $ref: "../swagger.yaml#/definitions/error"
(-)a/api/v1/swagger/paths/circulation_rules.yaml (+98 lines)
Line 0 Link Here
1
---
2
/circulation_rules:
3
  get:
4
    x-mojo-to: CirculationRules#list_effective_rules
5
    operationId: listCirculationRules
6
    tags:
7
      - circulation_rules
8
    summary: Get circulation rules for this item/library/patron combination
9
    produces:
10
      - application/json
11
    parameters:
12
      - name: item_type
13
        in: query
14
        description: The itemtype
15
        required: false
16
        type: string
17
      - name: library
18
        in: query
19
        description: The library code
20
        required: false
21
        type: string
22
      - name: patron_category
23
        in: query
24
        description: The patron category
25
        required: false
26
        type: string
27
      - name: rules
28
        in: query
29
        description: A comma-separated list of rule kinds
30
        required: false
31
        type: array
32
        items:
33
          type: string
34
        collectionFormat: multi
35
    responses:
36
      "200":
37
        description: A list of rules for this itemtype, library and patron category combination
38
        schema:
39
          type: object
40
          additionalProperties:
41
            type: [ 'string', 'integer' ]
42
      "400":
43
        description: Bad request
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
46
      "403":
47
        description: Access forbidden
48
        schema:
49
          $ref: "../swagger.yaml#/definitions/error"
50
      "500":
51
        description: |
52
          Internal server error. Possible `error_code` attribute values:
53
54
          * `internal_server_error`
55
        schema:
56
          $ref: "../swagger.yaml#/definitions/error"
57
      "503":
58
        description: Under maintenance
59
        schema:
60
          $ref: "../swagger.yaml#/definitions/error"
61
    x-koha-authorization:
62
      permissions:
63
        - circulate: circulate_remaining_permissions
64
/circulation_rules/kinds:
65
  get:
66
    x-mojo-to: CirculationRules#get_kinds
67
    operationId: getCirculationRuleKinds
68
    tags:
69
      - circulation_rules
70
    summary: Get circulation rules kinds
71
    produces:
72
      - application/json
73
    responses:
74
      "200":
75
        description: A map of rule kind information
76
        schema:
77
          type: object
78
          additionalProperties:
79
            $ref: "../swagger.yaml#/definitions/circ-rule-kind"
80
      "403":
81
        description: Access forbidden
82
        schema:
83
          $ref: "../swagger.yaml#/definitions/error"
84
      "500":
85
        description: |
86
          Internal server error. Possible `error_code` attribute values:
87
88
          * `internal_server_error`
89
        schema:
90
          $ref: "../swagger.yaml#/definitions/error"
91
      "503":
92
        description: Under maintenance
93
        schema:
94
          $ref: "../swagger.yaml#/definitions/error"
95
    x-koha-authorization:
96
      permissions:
97
        - circulate: circulate_remaining_permissions
98
(-)a/api/v1/swagger/swagger.yaml (-3 / +4 lines)
Lines 279-286 paths: Link Here
279
    $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal"
279
    $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal"
280
  "/checkouts/availability":
280
  "/checkouts/availability":
281
    $ref: "./paths/checkouts.yaml#/~1checkouts~1availability"
281
    $ref: "./paths/checkouts.yaml#/~1checkouts~1availability"
282
  /circulation-rules/kinds:
282
  /circulation_rules:
283
    $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds
283
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules
284
  /circulation_rules/kinds:
285
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules~1kinds
284
  /cities:
286
  /cities:
285
    $ref: ./paths/cities.yaml#/~1cities
287
    $ref: ./paths/cities.yaml#/~1cities
286
  "/cities/{city_id}":
288
  "/cities/{city_id}":
287
- 

Return to bug 36641