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

(-)a/Koha/REST/Plugin/Responses.pm (+23 lines)
Lines 77-82 Provides a generic method rendering the standard response for resource not found Link Here
77
            );
77
            );
78
        }
78
        }
79
    );
79
    );
80
81
=head3 render_invalid_parameter_value
82
83
    $c->render_invalid_parameter_value
84
85
Provides a generic method rendering the standard response for invalid parameter value passed.
86
87
=cut
88
89
    $app->helper(
90
        'render_invalid_parameter_value' => sub { 
91
            my ( $c, $path ) = @_;
92
93
            $c->render(
94
                status  => 400,
95
                openapi => {
96
                    error      => "Invalid parameter value",
97
                    error_code => 'invalid_parameter_value',
98
                    path => $path,
99
                },
100
            );
101
        }
102
    );
80
}
103
}
81
104
82
1;
105
1;
(-)a/Koha/REST/V1/CirculationRules.pm (-7 / +20 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-47 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
44
45
=head3 list_effective_rules
43
=head3 list_effective_rules
46
44
47
List all effective rules for the requested patron/item/branch combination
45
List all effective rules for the requested patron/item/branch combination
Lines 52-67 sub list_effective_rules { Link Here
52
    my $c = shift->openapi->valid_input or return;
50
    my $c = shift->openapi->valid_input or return;
53
51
54
    my $item_type       = $c->param('itemtype');
52
    my $item_type       = $c->param('itemtype');
55
    my $library         = $c->param('library');
53
    my $branchcode      = $c->param('library');
56
    my $patron_category = $c->param('category');
54
    my $patron_category = $c->param('category');
57
    my $rules           = $c->param('rules') // [ keys %{Koha::CirculationRules->rule_kinds} ];
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('/query/itemtype') unless $type;
60
    }
61
62
    if ($branchcode) {
63
        my $library = Koha::Libraries->find($branchcode);
64
        return $c->render_invalid_parameter_value('/query/library') unless $library;
65
    }
66
67
    if ($patron_category) {
68
        my $category = Koha::Patron::Categories->find($patron_category);
69
        return $c->render_invalid_parameter_value('/query/category') unless $category;
70
    }
58
71
59
    my $effective_rules = Koha::CirculationRules->get_effective_rules(
72
    my $effective_rules = Koha::CirculationRules->get_effective_rules(
60
        {
73
        {
61
            categorycode => $patron_category,
74
            categorycode => $patron_category,
62
            itemtype     => $item_type,
75
            itemtype     => $item_type,
63
            branchcode   => $library,
76
            branchcode   => $branchcode,
64
            rules => $rules
77
            rules        => $rules
65
        }
78
        }
66
    );
79
    );
67
80
(-)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 (-34 / +45 lines)
Lines 1-20 Link Here
1
---
1
---
2
/circulation-rules/kinds:
2
/circulation_rules:
3
  get:
3
  get:
4
    x-mojo-to: CirculationRules#get_kinds
4
    x-mojo-to: CirculationRules#list_effective_rules
5
    operationId: getCirculationRuleKinds
5
    operationId: listCirculationRules
6
    tags:
6
    tags:
7
      - circulation_rules
7
      - circulation_rules
8
    summary: Get circulation rules kinds
8
    summary: Get circulation rules for this item/library/patron combination
9
    produces:
9
    produces:
10
      - application/json
10
      - application/json
11
    parameters:
12
      - name: itemtype
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: 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: csv
11
    responses:
35
    responses:
12
      "200":
36
      "200":
13
        description: A map of rule kind information
37
        description: A list of rules for this itemtype, library and patron category combination
14
        schema:
38
        schema:
15
          type: object
39
          type: object
16
          additionalProperties:
40
          additionalProperties:
17
            $ref: "../swagger.yaml#/definitions/circ-rule-kind"
41
            type: [ 'string', 'integer' ]
42
      "400":
43
        description: Bad request
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
18
      "403":
46
      "403":
19
        description: Access forbidden
47
        description: Access forbidden
20
        schema:
48
        schema:
Lines 30-72 Link Here
30
        description: Under maintenance
58
        description: Under maintenance
31
        schema:
59
        schema:
32
          $ref: "../swagger.yaml#/definitions/error"
60
          $ref: "../swagger.yaml#/definitions/error"
33
/circulation-rules/{itemtype}/{library}/{category}:
61
    x-koha-authorization:
62
      permissions:
63
        - circulate: circulate_remaining_permissions
64
/circulation_rules/kinds:
34
  get:
65
  get:
35
    x-mojo-to: CirculationRules#list_effective_rules
66
    x-mojo-to: CirculationRules#get_kinds
36
    operationId: listCirculationRules
67
    operationId: getCirculationRuleKinds
37
    tags:
68
    tags:
38
      - circulation_rules
69
      - circulation_rules
39
    summary: Get circulation rules for this item/library/patron combination
70
    summary: Get circulation rules kinds
40
    produces:
71
    produces:
41
      - application/json
72
      - application/json
42
    parameters:
43
      - name: itemtype
44
        in: path
45
        description: The itemtype
46
        required: true
47
        type: string
48
      - name: library
49
        in: path
50
        description: The library code
51
        required: true
52
        type: string
53
      - name: category
54
        in: path
55
        description: The patron category
56
        required: true
57
        type: string
58
      - name: rules
59
        in: query
60
        description: A comma-separated list of rule kinds
61
        type: array
62
        items:
63
          type: string
64
        collectionFormat: csv
65
    responses:
73
    responses:
66
      "200":
74
      "200":
67
        description: A list of rules for this itemtype, library and patron category combination
75
        description: A map of rule kind information
68
        schema:
76
        schema:
69
          type: object
77
          type: object
78
          additionalProperties:
79
            $ref: "../swagger.yaml#/definitions/circ-rule-kind"
70
      "403":
80
      "403":
71
        description: Access forbidden
81
        description: Access forbidden
72
        schema:
82
        schema:
Lines 85-87 Link Here
85
    x-koha-authorization:
95
    x-koha-authorization:
86
      permissions:
96
      permissions:
87
        - circulate: circulate_remaining_permissions
97
        - circulate: circulate_remaining_permissions
98
(-)a/api/v1/swagger/swagger.yaml (-4 / +3 lines)
Lines 279-288 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:
283
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules
282
  /circulation-rules/kinds:
284
  /circulation-rules/kinds:
283
    $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds
285
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules~1kinds
284
  /circulation-rules/{itemtype}/{library}/{category}:
285
    $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1{itemtype}~1{library}~1{category}
286
  /cities:
286
  /cities:
287
    $ref: ./paths/cities.yaml#/~1cities
287
    $ref: ./paths/cities.yaml#/~1cities
288
  "/cities/{city_id}":
288
  "/cities/{city_id}":
289
- 

Return to bug 36641