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

(-)a/Koha/REST/V1/StockRotation/Rotas.pm (+139 lines)
Line 0 Link Here
1
package Koha::REST::V1::StockRotation::Rotas;
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 <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::StockRotationRotas;
23
24
use Try::Tiny qw( catch try );
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 list
31
32
=cut
33
34
sub list {
35
    my $c = shift->openapi->valid_input or return;
36
37
    return try {
38
        my $rotas = $c->objects->search( Koha::StockRotationRotas->new );
39
        return $c->render( status => 200, openapi => $rotas );
40
    } catch {
41
        $c->unhandled_exception($_);
42
    };
43
44
}
45
46
=head3 get
47
48
=cut
49
50
sub get {
51
    my $c = shift->openapi->valid_input or return;
52
53
    return try {
54
        my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
55
        unless ($rota) {
56
            return $c->render(
57
                status  => 404,
58
                openapi => { error => "Rota not found" }
59
            );
60
        }
61
62
        return $c->render( status => 200, openapi => $rota->to_api );
63
    } catch {
64
        $c->unhandled_exception($_);
65
    }
66
}
67
68
=head3 add
69
70
=cut
71
72
sub add {
73
    my $c = shift->openapi->valid_input or return;
74
75
    return try {
76
        my $rota = Koha::StockRotationRota->new_from_api( $c->req->json );
77
        $rota->store;
78
        $c->res->headers->location( $c->req->url->to_string . '/' . $rota->rota_id );
79
        return $c->render(
80
            status  => 201,
81
            openapi => $rota->to_api
82
        );
83
    } catch {
84
        $c->unhandled_exception($_);
85
    };
86
}
87
88
=head3 update
89
90
=cut
91
92
sub update {
93
    my $c = shift->openapi->valid_input or return;
94
95
    my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
96
97
    if ( not defined $rota ) {
98
        return $c->render(
99
            status  => 404,
100
            openapi => { error => "Object not found" }
101
        );
102
    }
103
104
    return try {
105
        $rota->set_from_api( $c->req->json );
106
        $rota->store();
107
        return $c->render( status => 200, openapi => $rota->to_api );
108
    } catch {
109
        $c->unhandled_exception($_);
110
    };
111
}
112
113
=head3 delete
114
115
=cut
116
117
sub delete {
118
    my $c = shift->openapi->valid_input or return;
119
120
    my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') );
121
    if ( not defined $rota ) {
122
        return $c->render(
123
            status  => 404,
124
            openapi => { error => "Object not found" }
125
        );
126
    }
127
128
    return try {
129
        $rota->delete;
130
        return $c->render(
131
            status  => 204,
132
            openapi => q{}
133
        );
134
    } catch {
135
        $c->unhandled_exception($_);
136
    };
137
}
138
139
1;
(-)a/api/v1/swagger/definitions/rota.yaml (+27 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  rota_id:
5
    type: integer
6
    description: internally assigned rota identifier
7
    readOnly: true
8
  title:
9
    description: rota title
10
    type: string
11
  description:
12
    description: rota description
13
    type:
14
      - string
15
      - "null"
16
  cyclical:
17
    description: rota is cyclical
18
    type: boolean
19
  active:
20
    description: rota is active
21
    type: boolean
22
additionalProperties: false
23
required:
24
  - title
25
  - description
26
  - cyclical
27
  - active
(-)a/api/v1/swagger/paths/rotas.yaml (-1 / +199 lines)
Lines 1-11 Link Here
1
---
1
---
2
"/rotas":
3
  get:
4
    x-mojo-to: StockRotation::Rotas#list
5
    operationId: listRotas
6
    tags:
7
      - stockrotation
8
    summary: List rotas
9
    produces:
10
      - application/json
11
    parameters:
12
      - $ref: "../swagger.yaml#/parameters/match"
13
      - $ref: "../swagger.yaml#/parameters/order_by"
14
      - $ref: "../swagger.yaml#/parameters/page"
15
      - $ref: "../swagger.yaml#/parameters/per_page"
16
      - $ref: "../swagger.yaml#/parameters/q_param"
17
      - $ref: "../swagger.yaml#/parameters/q_body"
18
      - $ref: "../swagger.yaml#/parameters/request_id_header"
19
    responses:
20
      "200":
21
        description: A list of stockrotation rotas
22
        schema:
23
          type: array
24
          items:
25
            $ref: "../swagger.yaml#/definitions/rota"
26
      "403":
27
        description: Access forbidden
28
        schema:
29
          $ref: "../swagger.yaml#/definitions/error"
30
      "500":
31
        description: |
32
          Internal server error. Possible `error_code` attribute values:
33
34
          * `internal_server_error`
35
        schema:
36
          $ref: "../swagger.yaml#/definitions/error"
37
      "503":
38
        description: Under maintenance
39
        schema:
40
          $ref: "../swagger.yaml#/definitions/error"
41
    x-koha-authorization:
42
      permissions:
43
        catalogue: "1"
44
  post:
45
    x-mojo-to: StockRotation::Rotas#add
46
    operationId: addRota
47
    tags:
48
      - stockrotation
49
    summary: Add rota
50
    parameters:
51
      - name: body
52
        in: body
53
        description: A JSON object containing informations about the new hold
54
        required: true
55
        schema:
56
          $ref: "../swagger.yaml#/definitions/rota"
57
    produces:
58
      - application/json
59
    responses:
60
      "201":
61
        description: Rota added
62
        schema:
63
          $ref: "../swagger.yaml#/definitions/rota"
64
      "401":
65
        description: Authentication required
66
        schema:
67
          $ref: "../swagger.yaml#/definitions/error"
68
      "403":
69
        description: Access forbidden
70
        schema:
71
          $ref: "../swagger.yaml#/definitions/error"
72
      "500":
73
        description: |
74
          Internal server error. Possible `error_code` attribute values:
75
76
          * `internal_server_error`
77
        schema:
78
          $ref: "../swagger.yaml#/definitions/error"
79
      "503":
80
        description: Under maintenance
81
        schema:
82
          $ref: "../swagger.yaml#/definitions/error"
83
    x-koha-authorization:
84
      permissions:
85
        stockrotation: "1"
86
"/rotas/{rota_id}":
87
  get:
88
    x-mojo-to: StockRotation::Rotas#get
89
    operationId: getRota
90
    tags:
91
      - stockrotation
92
    summary: Get rota
93
    parameters:
94
      - $ref: "../swagger.yaml#/parameters/rota_id_pp"
95
    produces:
96
      - application/json
97
    responses:
98
      "200":
99
        description: A rota
100
        schema:
101
          $ref: "../swagger.yaml#/definitions/rota"
102
      "404":
103
        description: Rota not found
104
        schema:
105
          $ref: "../swagger.yaml#/definitions/error"
106
      "500":
107
        description: |
108
          Internal server error. Possible `error_code` attribute values:
109
110
          * `internal_server_error`
111
        schema:
112
          $ref: "../swagger.yaml#/definitions/error"
113
      "503":
114
        description: Under maintenance
115
        schema:
116
          $ref: "../swagger.yaml#/definitions/error"
117
    x-koha-authorization:
118
      permissions:
119
        catalogue: "1"
120
  put:
121
    x-mojo-to: StockRotation::Rotas#update
122
    operationId: updateRota
123
    tags:
124
      - stockrotation
125
    summary: Update rota
126
    parameters:
127
      - $ref: "../swagger.yaml#/parameters/rota_id_pp"
128
      - name: body
129
        in: body
130
        description: A rota object
131
        required: true
132
        schema:
133
          $ref: "../swagger.yaml#/definitions/rota"
134
    produces:
135
      - application/json
136
    responses:
137
      "200":
138
        description: A rota
139
        schema:
140
          $ref: "../swagger.yaml#/definitions/rota"
141
      "401":
142
        description: Authentication required
143
        schema:
144
          $ref: "../swagger.yaml#/definitions/error"
145
      "403":
146
        description: Access forbidden
147
        schema:
148
          $ref: "../swagger.yaml#/definitions/error"
149
      "404":
150
        description: Rota not found
151
        schema:
152
          $ref: "../swagger.yaml#/definitions/error"
153
      "500":
154
        description: Internal error
155
        schema:
156
          $ref: "../swagger.yaml#/definitions/error"
157
      "503":
158
        description: Under maintenance
159
        schema:
160
          $ref: "../swagger.yaml#/definitions/error"
161
    x-koha-authorization:
162
      permissions:
163
        stockrotation: "1"
164
  delete:
165
    x-mojo-to: StockRotation::Rotas#delete
166
    operationId: deleteRota
167
    tags:
168
      - stockrotation
169
    summary: Delete rota
170
    parameters:
171
      - $ref: "../swagger.yaml#/parameters/rota_id_pp"
172
    produces:
173
      - application/json
174
    responses:
175
      "204":
176
        description: Rota deleted
177
      "401":
178
        description: Authentication required
179
        schema:
180
          $ref: "../swagger.yaml#/definitions/error"
181
      "403":
182
        description: Access forbidden
183
        schema:
184
          $ref: "../swagger.yaml#/definitions/error"
185
      "404":
186
        description: Rota not found
187
        schema:
188
          $ref: "../swagger.yaml#/definitions/error"
189
      "500":
190
        description: Internal error
191
        schema:
192
          $ref: "../swagger.yaml#/definitions/error"
193
      "503":
194
        description: Under maintenance
195
        schema:
196
          $ref: "../swagger.yaml#/definitions/error"
197
    x-koha-authorization:
198
      permissions:
199
        stockrotation: "1"
2
"/rotas/{rota_id}/stages/{stage_id}/position":
200
"/rotas/{rota_id}/stages/{stage_id}/position":
3
  put:
201
  put:
4
    x-mojo-to: StockRotation::Stage#move
202
    x-mojo-to: StockRotation::Stage#move
5
    operationId: moveStage
203
    operationId: moveStage
6
    summary: Update stage
204
    summary: Update stage
7
    tags:
205
    tags:
8
      - rotas
206
      - stockrotation
9
    parameters:
207
    parameters:
10
      - name: rota_id
208
      - name: rota_id
11
        in: path
209
        in: path
(-)a/api/v1/swagger/swagger.yaml (-3 / +14 lines)
Lines 144-149 definitions: Link Here
144
    $ref: ./definitions/renewals.yaml
144
    $ref: ./definitions/renewals.yaml
145
  return_claim:
145
  return_claim:
146
    $ref: ./definitions/return_claim.yaml
146
    $ref: ./definitions/return_claim.yaml
147
  rota:
148
    $ref: ./definitions/rota.yaml
147
  search_filter:
149
  search_filter:
148
    $ref: ./definitions/search_filter.yaml
150
    $ref: ./definitions/search_filter.yaml
149
  smtp_server:
151
  smtp_server:
Lines 487-492 paths: Link Here
487
    $ref: "./paths/return_claims.yaml#/~1return_claims~1{claim_id}~1notes"
489
    $ref: "./paths/return_claims.yaml#/~1return_claims~1{claim_id}~1notes"
488
  "/return_claims/{claim_id}/resolve":
490
  "/return_claims/{claim_id}/resolve":
489
    $ref: "./paths/return_claims.yaml#/~1return_claims~1{claim_id}~1resolve"
491
    $ref: "./paths/return_claims.yaml#/~1return_claims~1{claim_id}~1resolve"
492
  "/rotas":
493
    $ref: "./paths/rotas.yaml#/~1rotas"
494
  "/rotas/{rota_id}":
495
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}"
490
  "/rotas/{rota_id}/stages/{stage_id}/position":
496
  "/rotas/{rota_id}/stages/{stage_id}/position":
491
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position"
497
    $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position"
492
  /suggestions:
498
  /suggestions:
Lines 833-838 parameters: Link Here
833
    name: x-koha-request-id
839
    name: x-koha-request-id
834
    required: false
840
    required: false
835
    type: integer
841
    type: integer
842
  rota_id_pp:
843
    description: Rota internal identifier
844
    in: path
845
    name: rota_id
846
    required: true
847
    type: integer
836
  search_filter_id_pp:
848
  search_filter_id_pp:
837
    name: search_filter_id
849
    name: search_filter_id
838
    in: path
850
    in: path
Lines 1145-1152 tags: Link Here
1145
  - description: "Manage return claims\n"
1157
  - description: "Manage return claims\n"
1146
    name: return_claims
1158
    name: return_claims
1147
    x-displayName: Return claims
1159
    x-displayName: Return claims
1148
  - description: "Manage rotas\n"
1160
  - description: "Manage stock rotation\n"
1149
    name: rotas
1161
    name: stockrotation
1150
    x-displayName: Rotas
1162
    x-displayName: Rotas
1151
  - description: "Manage search filters"
1163
  - description: "Manage search filters"
1152
    name: search_filters
1164
    name: search_filters
1153
- 

Return to bug 35430