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

(-)a/Koha/REST/V1/Acquisitions/Orders.pm (-29 / +8 lines)
Lines 95-101 Controller function that handles retrieving a single Koha::Acquisition::Order ob Link Here
95
sub get {
95
sub get {
96
    my $c = shift->openapi->valid_input or return;
96
    my $c = shift->openapi->valid_input or return;
97
97
98
    my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
98
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
99
99
100
    unless ($order) {
100
    unless ($order) {
101
        return $c->render(
101
        return $c->render(
Lines 105-115 sub get { Link Here
105
    }
105
    }
106
106
107
    return try {
107
    return try {
108
        my $embed = $c->stash('koha.embed');
109
110
        return $c->render(
108
        return $c->render(
111
            status  => 200,
109
            status  => 200,
112
            openapi => $order->to_api({ embed => $embed })
110
            openapi => $c->objects->to_api( $order ),
113
        );
111
        );
114
    }
112
    }
115
    catch {
113
    catch {
Lines 127-133 sub add { Link Here
127
    my $c = shift->openapi->valid_input or return;
125
    my $c = shift->openapi->valid_input or return;
128
126
129
    return try {
127
    return try {
130
        my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
128
        my $order = Koha::Acquisition::Order->new_from_api( $c->req->json );
131
        $order->store->discard_changes;
129
        $order->store->discard_changes;
132
130
133
        $c->res->headers->location(
131
        $c->res->headers->location(
Lines 136-142 sub add { Link Here
136
134
137
        return $c->render(
135
        return $c->render(
138
            status  => 201,
136
            status  => 201,
139
            openapi => $order->to_api
137
            openapi => $c->objects->to_api( $order ),
140
        );
138
        );
141
    }
139
    }
142
    catch {
140
    catch {
Lines 160-166 Controller function that handles updating a Koha::Acquisition::Order object Link Here
160
sub update {
158
sub update {
161
    my $c = shift->openapi->valid_input or return;
159
    my $c = shift->openapi->valid_input or return;
162
160
163
    my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
161
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
164
162
165
    unless ($order) {
163
    unless ($order) {
166
        return $c->render(
164
        return $c->render(
Lines 170-181 sub update { Link Here
170
    }
168
    }
171
169
172
    return try {
170
    return try {
173
        $order->set_from_api( $c->validation->param('body') );
171
        $order->set_from_api( $c->req->json );
174
        $order->store()->discard_changes;
172
        $order->store()->discard_changes;
175
173
176
        return $c->render(
174
        return $c->render(
177
            status  => 200,
175
            status  => 200,
178
            openapi => $order->to_api
176
            openapi => $c->objects->to_api( $order ),
179
        );
177
        );
180
    }
178
    }
181
    catch {
179
    catch {
Lines 192-198 Controller function that handles deleting a Koha::Patron object Link Here
192
sub delete {
190
sub delete {
193
    my $c = shift->openapi->valid_input or return;
191
    my $c = shift->openapi->valid_input or return;
194
192
195
    my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
193
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
196
194
197
    unless ($order) {
195
    unless ($order) {
198
        return $c->render(
196
        return $c->render(
Lines 215-237 sub delete { Link Here
215
    };
213
    };
216
}
214
}
217
215
218
=head2 Internal methods
219
220
=head3 table_name_fixer
221
222
    $q = $c->table_name_fixer( $q );
223
224
The Koha::Biblio representation includes the biblioitem.* attributes. This is handy
225
for API consumers but as they are different tables, converting the queries that mention
226
biblioitem columns can be tricky. This method renames known column names as used on Koha's
227
UI.
228
229
=cut
230
231
sub table_name_fixer {
232
    my ( $self, $q ) = @_;
233
    $q =~ s/biblio\.(?=isbn|ean|publisher)/biblio.biblioitem./g;
234
    return $q;
235
}
236
237
1;
216
1;
(-)a/Koha/REST/V1/Acquisitions/Vendors.pm (-8 / +9 lines)
Lines 62-71 Controller function that handles retrieving a single Koha::Acquisition::Booksell Link Here
62
sub get {
62
sub get {
63
    my $c = shift->openapi->valid_input or return;
63
    my $c = shift->openapi->valid_input or return;
64
64
65
    my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
65
    my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
66
    unless ($vendor) {
66
    unless ($vendor) {
67
        return $c->render( status  => 404,
67
        return $c->render(
68
                           openapi => { error => "Vendor not found" } );
68
            status  => 404,
69
            openapi => { error => "Vendor not found" }
70
        );
69
    }
71
    }
70
72
71
    return try {
73
    return try {
Lines 88-94 Controller function that handles adding a new Koha::Acquisition::Bookseller obje Link Here
88
sub add {
90
sub add {
89
    my $c = shift->openapi->valid_input or return;
91
    my $c = shift->openapi->valid_input or return;
90
92
91
    my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->validation->param('body') );
93
    my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
92
94
93
    return try {
95
    return try {
94
        $vendor->store;
96
        $vendor->store;
Lines 115-122 sub update { Link Here
115
    my $vendor;
117
    my $vendor;
116
118
117
    return try {
119
    return try {
118
        $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
120
        $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
119
        $vendor->set_from_api( $c->validation->param('body') );
121
        $vendor->set_from_api( $c->req->json );
120
        $vendor->store();
122
        $vendor->store();
121
        return $c->render(
123
        return $c->render(
122
            status  => 200,
124
            status  => 200,
Lines 132-138 sub update { Link Here
132
        }
134
        }
133
135
134
        $c->unhandled_exception($_);
136
        $c->unhandled_exception($_);
135
136
    };
137
    };
137
138
138
}
139
}
Lines 147-153 sub delete { Link Here
147
    my $c = shift->openapi->valid_input or return;
148
    my $c = shift->openapi->valid_input or return;
148
149
149
    return try {
150
    return try {
150
        my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
151
        my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
151
152
152
        unless ( $vendor ) {
153
        unless ( $vendor ) {
153
            return $c->render(
154
            return $c->render(
(-)a/Koha/REST/V1/AdvancedEditorMacro.pm (-20 / +26 lines)
Lines 66-77 Controller function that handles retrieving a single Koha::AdvancedEditorMacro Link Here
66
sub get {
66
sub get {
67
    my $c = shift->openapi->valid_input or return;
67
    my $c = shift->openapi->valid_input or return;
68
    my $patron = $c->stash('koha.user');
68
    my $patron = $c->stash('koha.user');
69
    my $macro = Koha::AdvancedEditorMacros->find({
69
    my $macro  = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
70
        id => $c->validation->param('advancededitormacro_id'),
71
    });
72
    unless ($macro) {
70
    unless ($macro) {
73
        return $c->render( status  => 404,
71
        return $c->render(
74
                           openapi => { error => "Macro not found" } );
72
            status  => 404,
73
            openapi => { error => "Macro not found" }
74
        );
75
    }
75
    }
76
    if( $macro->shared ){
76
    if( $macro->shared ){
77
        return $c->render( status => 403, openapi => {
77
        return $c->render( status => 403, openapi => {
Lines 97-103 sub get_shared { Link Here
97
    my $c = shift->openapi->valid_input or return;
97
    my $c = shift->openapi->valid_input or return;
98
    my $patron = $c->stash('koha.user');
98
    my $patron = $c->stash('koha.user');
99
    my $macro = Koha::AdvancedEditorMacros->find({
99
    my $macro = Koha::AdvancedEditorMacros->find({
100
        id => $c->validation->param('advancededitormacro_id'),
100
        id => $c->param('advancededitormacro_id'),
101
    });
101
    });
102
    unless ($macro) {
102
    unless ($macro) {
103
        return $c->render( status  => 404,
103
        return $c->render( status  => 404,
Lines 120-132 Controller function that handles adding a new Koha::AdvancedEditorMacro object Link Here
120
sub add {
120
sub add {
121
    my $c = shift->openapi->valid_input or return;
121
    my $c = shift->openapi->valid_input or return;
122
122
123
    if( defined $c->validation->param('body')->{shared} && $c->validation->param('body')->{shared} == 1 ){
123
    my $body = $c->req->json;
124
125
    if( defined $body->{shared} && $body->{shared} == 1 ){
124
        return $c->render( status  => 403,
126
        return $c->render( status  => 403,
125
                           openapi => { error => "To create shared macros you must use advancededitor/shared" } );
127
                           openapi => { error => "To create shared macros you must use advancededitor/shared" } );
126
    }
128
    }
127
129
128
    return try {
130
    return try {
129
        my $macro = Koha::AdvancedEditorMacro->new_from_api( $c->validation->param('body') );
131
        my $macro = Koha::AdvancedEditorMacro->new_from_api( $body );
130
        $macro->store->discard_changes;
132
        $macro->store->discard_changes;
131
        $c->res->headers->location( $c->req->url->to_string . '/' . $macro->id );
133
        $c->res->headers->location( $c->req->url->to_string . '/' . $macro->id );
132
        return $c->render(
134
        return $c->render(
Lines 148-159 Controller function that handles adding a new shared Koha::AdvancedEditorMacro o Link Here
148
sub add_shared {
150
sub add_shared {
149
    my $c = shift->openapi->valid_input or return;
151
    my $c = shift->openapi->valid_input or return;
150
152
151
    unless( defined $c->validation->param('body')->{shared} && $c->validation->param('body')->{shared} == 1 ){
153
    my $body = $c->req->json;
154
155
    unless( defined $body->{shared} && $body->{shared} == 1 ){
152
        return $c->render( status  => 403,
156
        return $c->render( status  => 403,
153
                           openapi => { error => "To create private macros you must use advancededitor" } );
157
                           openapi => { error => "To create private macros you must use advancededitor" } );
154
    }
158
    }
155
    return try {
159
    return try {
156
        my $macro = Koha::AdvancedEditorMacro->new_from_api( $c->validation->param('body') );
160
        my $macro = Koha::AdvancedEditorMacro->new_from_api( $body );
157
        $macro->store->discard_changes;
161
        $macro->store->discard_changes;
158
        $c->res->headers->location( $c->req->url->to_string . '/' . $macro->id );
162
        $c->res->headers->location( $c->req->url->to_string . '/' . $macro->id );
159
        return $c->render(
163
        return $c->render(
Lines 175-181 Controller function that handles updating a Koha::AdvancedEditorMacro object Link Here
175
sub update {
179
sub update {
176
    my $c = shift->openapi->valid_input or return;
180
    my $c = shift->openapi->valid_input or return;
177
181
178
    my $macro = Koha::AdvancedEditorMacros->find( $c->validation->param('advancededitormacro_id') );
182
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
179
183
180
    if ( not defined $macro ) {
184
    if ( not defined $macro ) {
181
        return $c->render( status  => 404,
185
        return $c->render( status  => 404,
Lines 183-189 sub update { Link Here
183
    }
187
    }
184
    my $patron = $c->stash('koha.user');
188
    my $patron = $c->stash('koha.user');
185
189
186
    if( $macro->shared == 1 || defined $c->validation->param('body')->{shared} && $c->validation->param('body')->{shared} == 1 ){
190
    my $body = $c->req->json;
191
192
    if( $macro->shared == 1 || defined $body->{shared} && $body->{shared} == 1 ){
187
        return $c->render( status  => 403,
193
        return $c->render( status  => 403,
188
                           openapi => { error => "To update a macro as shared you must use the advanced_editor/macros/shared endpoint" } );
194
                           openapi => { error => "To update a macro as shared you must use the advanced_editor/macros/shared endpoint" } );
189
    } else {
195
    } else {
Lines 194-201 sub update { Link Here
194
    }
200
    }
195
201
196
    return try {
202
    return try {
197
        my $params = $c->req->json;
203
        $macro->set_from_api( $body );
198
        $macro->set_from_api( $params );
199
        $macro->store->discard_changes;
204
        $macro->store->discard_changes;
200
        return $c->render( status => 200, openapi => $macro->to_api );
205
        return $c->render( status => 200, openapi => $macro->to_api );
201
    }
206
    }
Lines 213-233 Controller function that handles updating a shared Koha::AdvancedEditorMacro obj Link Here
213
sub update_shared {
218
sub update_shared {
214
    my $c = shift->openapi->valid_input or return;
219
    my $c = shift->openapi->valid_input or return;
215
220
216
    my $macro = Koha::AdvancedEditorMacros->find( $c->validation->param('advancededitormacro_id') );
221
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
222
223
    my $body = $c->req->json;
217
224
218
    if ( not defined $macro ) {
225
    if ( not defined $macro ) {
219
        return $c->render( status  => 404,
226
        return $c->render( status  => 404,
220
                           openapi => { error => "Object not found" } );
227
                           openapi => { error => "Object not found" } );
221
    }
228
    }
222
229
223
    unless( $macro->shared == 1 || defined $c->validation->param('body')->{shared} && $c->validation->param('body')->{shared} == 1 ){
230
    unless( $macro->shared == 1 || defined $body->{shared} && $body->{shared} == 1 ){
224
        return $c->render( status  => 403,
231
        return $c->render( status  => 403,
225
                           openapi => { error => "You can only update shared macros using this endpoint" } );
232
                           openapi => { error => "You can only update shared macros using this endpoint" } );
226
    }
233
    }
227
234
228
    return try {
235
    return try {
229
        my $params = $c->req->json;
236
        $macro->set_from_api( $body );
230
        $macro->set_from_api( $params );
231
        $macro->store->discard_changes;
237
        $macro->store->discard_changes;
232
        return $c->render( status => 200, openapi => $macro->to_api );
238
        return $c->render( status => 200, openapi => $macro->to_api );
233
    }
239
    }
Lines 245-251 Controller function that handles deleting a Koha::AdvancedEditorMacro object Link Here
245
sub delete {
251
sub delete {
246
    my $c = shift->openapi->valid_input or return;
252
    my $c = shift->openapi->valid_input or return;
247
253
248
    my $macro = Koha::AdvancedEditorMacros->find( $c->validation->param('advancededitormacro_id') );
254
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
249
    if ( not defined $macro ) {
255
    if ( not defined $macro ) {
250
        return $c->render( status  => 404,
256
        return $c->render( status  => 404,
251
                           openapi => { error => "Object not found" } );
257
                           openapi => { error => "Object not found" } );
Lines 280-286 Controller function that handles deleting a shared Koha::AdvancedEditorMacro obj Link Here
280
sub delete_shared {
286
sub delete_shared {
281
    my $c = shift->openapi->valid_input or return;
287
    my $c = shift->openapi->valid_input or return;
282
288
283
    my $macro = Koha::AdvancedEditorMacros->find( $c->validation->param('advancededitormacro_id') );
289
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
284
    if ( not defined $macro ) {
290
    if ( not defined $macro ) {
285
        return $c->render( status  => 404,
291
        return $c->render( status  => 404,
286
                           openapi => { error => "Object not found" } );
292
                           openapi => { error => "Object not found" } );
(-)a/Koha/REST/V1/ArticleRequests.pm (-7 / +7 lines)
Lines 42-48 Controller function that handles cancelling a Koha::ArticleRequest object Link Here
42
sub cancel {
42
sub cancel {
43
    my $c = shift->openapi->valid_input or return;
43
    my $c = shift->openapi->valid_input or return;
44
44
45
    my $article_request = Koha::ArticleRequests->find( $c->validation->param('article_request_id') );
45
    my $article_request = Koha::ArticleRequests->find( $c->param('article_request_id') );
46
46
47
    unless ( $article_request ) {
47
    unless ( $article_request ) {
48
        return $c->render(
48
        return $c->render(
Lines 51-58 sub cancel { Link Here
51
        );
51
        );
52
    }
52
    }
53
53
54
    my $reason = $c->validation->param('cancellation_reason');
54
    my $reason = $c->param('cancellation_reason');
55
    my $notes  = $c->validation->param('notes');
55
    my $notes  = $c->param('notes');
56
56
57
    return try {
57
    return try {
58
58
Lines 80-86 Controller function that handles cancelling a patron's Koha::ArticleRequest obje Link Here
80
sub patron_cancel {
80
sub patron_cancel {
81
    my $c = shift->openapi->valid_input or return;
81
    my $c = shift->openapi->valid_input or return;
82
82
83
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
83
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
84
84
85
    unless ( $patron ) {
85
    unless ( $patron ) {
86
        return $c->render(
86
        return $c->render(
Lines 91-97 sub patron_cancel { Link Here
91
91
92
    # patron_id has been validated by the allow-owner check, so the following call to related
92
    # patron_id has been validated by the allow-owner check, so the following call to related
93
    # article requests covers the case of article requests not belonging to the patron
93
    # article requests covers the case of article requests not belonging to the patron
94
    my $article_request = $patron->article_requests->find( $c->validation->param('article_request_id') );
94
    my $article_request = $patron->article_requests->find( $c->param('article_request_id') );
95
95
96
    unless ( $article_request ) {
96
    unless ( $article_request ) {
97
        return $c->render(
97
        return $c->render(
Lines 100-107 sub patron_cancel { Link Here
100
        );
100
        );
101
    }
101
    }
102
102
103
    my $reason = $c->validation->param('cancellation_reason');
103
    my $reason = $c->param('cancellation_reason');
104
    my $notes  = $c->validation->param('notes');
104
    my $notes  = $c->param('notes');
105
105
106
    return try {
106
    return try {
107
107
(-)a/Koha/REST/V1/Auth/Identity/Provider/Domains.pm (-17 / +16 lines)
Lines 44-51 sub list { Link Here
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    return try {
46
    return try {
47
        my $identity_provider_id = $c->validation->param('identity_provider_id');
47
        my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
48
        my $provider         = Koha::Auth::Identity::Providers->find($identity_provider_id);
49
48
50
        unless ($provider) {
49
        unless ($provider) {
51
            return $c->render(
50
            return $c->render(
Lines 78-85 sub get { Link Here
78
77
79
    return try {
78
    return try {
80
79
81
        my $identity_provider_id = $c->validation->param('identity_provider_id');
80
        my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
82
        my $provider         = Koha::Auth::Identity::Providers->find($identity_provider_id);
83
81
84
        unless ($provider) {
82
        unless ($provider) {
85
            return $c->render(
83
            return $c->render(
Lines 93-100 sub get { Link Here
93
91
94
        my $domains_rs = $provider->domains;
92
        my $domains_rs = $provider->domains;
95
93
96
        my $identity_provider_domain_id = $c->validation->param('identity_provider_domain_id');
94
        my $domain = $c->objects->find( $domains_rs, $c->param('identity_provider_domain_id') );
97
        my $domain                  = $c->objects->find( $domains_rs, $identity_provider_domain_id );
98
95
99
        unless ($domain) {
96
        unless ($domain) {
100
            return $c->render(
97
            return $c->render(
Lines 122-129 sub add { Link Here
122
    my $c = shift->openapi->valid_input or return;
119
    my $c = shift->openapi->valid_input or return;
123
120
124
    return try {
121
    return try {
125
        my $params = $c->validation->param('body');
122
        my $params = $c->req->json;
126
        $params->{identity_provider_id} = $c->validation->param('identity_provider_id');
123
        $params->{identity_provider_id} = $c->param('identity_provider_id');
127
        Koha::Database->new->schema->txn_do(
124
        Koha::Database->new->schema->txn_do(
128
            sub {
125
            sub {
129
                my $domain = Koha::Auth::Identity::Provider::Domain->new_from_api( $params );
126
                my $domain = Koha::Auth::Identity::Provider::Domain->new_from_api( $params );
Lines 160-170 Controller method for updating an identity provider domain. Link Here
160
sub update {
157
sub update {
161
    my $c = shift->openapi->valid_input or return;
158
    my $c = shift->openapi->valid_input or return;
162
159
163
    my $identity_provider_id        = $c->validation->param('identity_provider_id');
164
    my $identity_provider_domain_id = $c->validation->param('identity_provider_domain_id');
165
166
    my $domain = Koha::Auth::Identity::Provider::Domains->find(
160
    my $domain = Koha::Auth::Identity::Provider::Domains->find(
167
        { identity_provider_id => $identity_provider_id, identity_provider_domain_id => $identity_provider_domain_id } );
161
        {
162
            identity_provider_id        => $c->param('identity_provider_id'),
163
            identity_provider_domain_id => $c->param('identity_provider_domain_id')
164
        }
165
    );
168
166
169
    unless ($domain) {
167
    unless ($domain) {
170
        return $c->render(
168
        return $c->render(
Lines 181-187 sub update { Link Here
181
        Koha::Database->new->schema->txn_do(
179
        Koha::Database->new->schema->txn_do(
182
            sub {
180
            sub {
183
181
184
                $domain->set_from_api( $c->validation->param('body') );
182
                $domain->set_from_api( $c->req->json );
185
                $domain->store->discard_changes;
183
                $domain->store->discard_changes;
186
184
187
                return $c->render(
185
                return $c->render(
Lines 204-214 Controller method for deleting an identity provider. Link Here
204
sub delete {
202
sub delete {
205
    my $c = shift->openapi->valid_input or return;
203
    my $c = shift->openapi->valid_input or return;
206
204
207
    my $identity_provider_id        = $c->validation->param('identity_provider_id');
208
    my $identity_provider_domain_id = $c->validation->param('identity_provider_domain_id');
209
210
    my $domain = Koha::Auth::Identity::Provider::Domains->find(
205
    my $domain = Koha::Auth::Identity::Provider::Domains->find(
211
        { identity_provider_id => $identity_provider_id, identity_provider_domain_id => $identity_provider_domain_id } );
206
        {
207
            identity_provider_id        => $c->param('identity_provider_id'),
208
            identity_provider_domain_id => $c->param('identity_provider_domain_id')
209
        }
210
    );
212
211
213
    unless ($domain) {
212
    unless ($domain) {
214
        return $c->render(
213
        return $c->render(
(-)a/Koha/REST/V1/Auth/Identity/Providers.pm (-7 / +5 lines)
Lines 66-73 sub get { Link Here
66
66
67
    return try {
67
    return try {
68
68
69
        my $identity_provider_id = $c->validation->param('identity_provider_id');
69
        my $provider = $c->objects->find( Koha::Auth::Identity::Providers->new, $c->param('identity_provider_id') );
70
        my $provider = $c->objects->find( Koha::Auth::Identity::Providers->new, $identity_provider_id );
71
70
72
        unless ( $provider ) {
71
        unless ( $provider ) {
73
            return $c->render(
72
            return $c->render(
Lines 100-106 sub add { Link Here
100
        Koha::Database->new->schema->txn_do(
99
        Koha::Database->new->schema->txn_do(
101
            sub {
100
            sub {
102
101
103
                my $body = $c->validation->param('body');
102
                my $body = $c->req->json;
104
103
105
                my $config   = delete $body->{config};
104
                my $config   = delete $body->{config};
106
                my $mapping  = delete $body->{mapping};
105
                my $mapping  = delete $body->{mapping};
Lines 147-154 Controller method for updating an identity provider. Link Here
147
sub update {
146
sub update {
148
    my $c = shift->openapi->valid_input or return;
147
    my $c = shift->openapi->valid_input or return;
149
148
150
    my $identity_provider_id = $c->validation->param('identity_provider_id');
149
    my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
151
    my $provider = Koha::Auth::Identity::Providers->find( $identity_provider_id );
152
150
153
    unless ( $provider ) {
151
    unless ( $provider ) {
154
        return $c->render(
152
        return $c->render(
Lines 165-171 sub update { Link Here
165
        Koha::Database->new->schema->txn_do(
163
        Koha::Database->new->schema->txn_do(
166
            sub {
164
            sub {
167
165
168
                my $body = $c->validation->param('body');
166
                my $body = $c->req->json;
169
167
170
                my $config   = delete $body->{config};
168
                my $config   = delete $body->{config};
171
                my $mapping  = delete $body->{mapping};
169
                my $mapping  = delete $body->{mapping};
Lines 211-217 Controller method for deleting an identity provider. Link Here
211
sub delete {
209
sub delete {
212
    my $c = shift->openapi->valid_input or return;
210
    my $c = shift->openapi->valid_input or return;
213
211
214
    my $provider = Koha::Auth::Identity::Providers->find( $c->validation->param('identity_provider_id') );
212
    my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
215
    unless ( $provider ) {
213
    unless ( $provider ) {
216
        return $c->render(
214
        return $c->render(
217
            status  => 404,
215
            status  => 404,
(-)a/Koha/REST/V1/Auth/Password.pm (-1 / +1 lines)
Lines 40-46 Controller method that checks a patron's password Link Here
40
40
41
sub validate {
41
sub validate {
42
    my $c = shift->openapi->valid_input or return;
42
    my $c = shift->openapi->valid_input or return;
43
    my $body   = $c->validation->param('body');
43
    my $body   = $c->req->json;
44
    my $userid = $body->{userid} // '';
44
    my $userid = $body->{userid} // '';
45
    my $patron = Koha::Patrons->find({ userid => $userid });
45
    my $patron = Koha::Patrons->find({ userid => $userid });
46
46
(-)a/Koha/REST/V1/AuthorisedValues.pm (-3 / +1 lines)
Lines 36-44 This routine returns the authorised values for a given category Link Here
36
sub list_av_from_category {
36
sub list_av_from_category {
37
    my $c = shift->openapi->valid_input or return;
37
    my $c = shift->openapi->valid_input or return;
38
38
39
    my $category_name = $c->validation->param('authorised_value_category_name');
39
    my $category = Koha::AuthorisedValueCategories->find($c->param('authorised_value_category_name'));
40
41
    my $category = Koha::AuthorisedValueCategories->find($category_name);
42
40
43
    unless ($category) {
41
    unless ($category) {
44
        return $c->render(
42
        return $c->render(
(-)a/Koha/REST/V1/Authorities.pm (-3 / +3 lines)
Lines 40-46 Controller function that handles retrieving a single authority object Link Here
40
sub get {
40
sub get {
41
    my $c = shift->openapi->valid_input or return;
41
    my $c = shift->openapi->valid_input or return;
42
42
43
    my $authority = Koha::Authorities->find( { authid => $c->validation->param('authority_id') } );
43
    my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
44
    unless ( $authority ) {
44
    unless ( $authority ) {
45
        return $c->render(
45
        return $c->render(
46
            status  => 404,
46
            status  => 404,
Lines 109-115 Controller function that handles deleting an authority object Link Here
109
sub delete {
109
sub delete {
110
    my $c = shift->openapi->valid_input or return;
110
    my $c = shift->openapi->valid_input or return;
111
111
112
    my $authority = Koha::Authorities->find( { authid => $c->validation->param('authority_id') } );
112
    my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
113
113
114
    if ( not defined $authority ) {
114
    if ( not defined $authority ) {
115
        return $c->render(
115
        return $c->render(
Lines 203-209 Controller function that handles modifying an authority object Link Here
203
sub update {
203
sub update {
204
    my $c = shift->openapi->valid_input or return;
204
    my $c = shift->openapi->valid_input or return;
205
205
206
    my $authid = $c->validation->param('authority_id');
206
    my $authid = $c->param('authority_id');
207
    my $authority = Koha::Authorities->find( { authid => $authid } );
207
    my $authority = Koha::Authorities->find( { authid => $authid } );
208
208
209
    if ( not defined $authority ) {
209
    if ( not defined $authority ) {
(-)a/Koha/REST/V1/BackgroundJobs.pm (-2 / +3 lines)
Lines 38-44 sub list { Link Here
38
38
39
    return try {
39
    return try {
40
40
41
        my $only_current = delete $c->validation->output->{only_current};
41
        my $only_current = $c->param('only_current');
42
        $c->req->params->remove('only_current');
42
43
43
        my $bj_rs = Koha::BackgroundJobs->new;
44
        my $bj_rs = Koha::BackgroundJobs->new;
44
45
Lines 66-72 sub get { Link Here
66
67
67
    return try {
68
    return try {
68
69
69
        my $job_id = $c->validation->param('job_id');
70
        my $job_id = $c->param('job_id');
70
        my $patron = $c->stash('koha.user');
71
        my $patron = $c->stash('koha.user');
71
72
72
        my $can_manage_background_jobs =
73
        my $can_manage_background_jobs =
(-)a/Koha/REST/V1/Biblios.pm (-25 / +26 lines)
Lines 53-59 sub get { Link Here
53
    $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed
53
    $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed
54
        unless $c->req->headers->accept =~ m/application\/json/;
54
        unless $c->req->headers->accept =~ m/application\/json/;
55
55
56
    my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, $attributes );
56
    my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
57
57
58
    unless ( $biblio ) {
58
    unless ( $biblio ) {
59
        return $c->render(
59
        return $c->render(
Lines 125-131 Controller function that handles deleting a biblio object Link Here
125
sub delete {
125
sub delete {
126
    my $c = shift->openapi->valid_input or return;
126
    my $c = shift->openapi->valid_input or return;
127
127
128
    my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') );
128
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
129
129
130
    if ( not defined $biblio ) {
130
    if ( not defined $biblio ) {
131
        return $c->render(
131
        return $c->render(
Lines 162-168 sub get_public { Link Here
162
    my $c = shift->openapi->valid_input or return;
162
    my $c = shift->openapi->valid_input or return;
163
163
164
    my $biblio = Koha::Biblios->find(
164
    my $biblio = Koha::Biblios->find(
165
        { biblionumber => $c->validation->param('biblio_id') },
165
        { biblionumber => $c->param('biblio_id') },
166
        { prefetch     => ['metadata'] } );
166
        { prefetch     => ['metadata'] } );
167
167
168
    unless ($biblio) {
168
    unless ($biblio) {
Lines 255-261 Controller function that handles retrieving biblio's items Link Here
255
sub get_items {
255
sub get_items {
256
    my $c = shift->openapi->valid_input or return;
256
    my $c = shift->openapi->valid_input or return;
257
257
258
    my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, { prefetch => ['items'] } );
258
    my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } );
259
259
260
    unless ( $biblio ) {
260
    unless ( $biblio ) {
261
        return $c->render(
261
        return $c->render(
Lines 268-275 sub get_items { Link Here
268
268
269
    return try {
269
    return try {
270
270
271
        my $items_rs = $biblio->items;
271
        my $items = $c->objects->search( $biblio->items );
272
        my $items    = $c->objects->search( $items_rs );
273
        return $c->render(
272
        return $c->render(
274
            status  => 200,
273
            status  => 200,
275
            openapi => $items
274
            openapi => $items
Lines 290-296 sub add_item { Link Here
290
    my $c = shift->openapi->valid_input or return;
289
    my $c = shift->openapi->valid_input or return;
291
290
292
    try {
291
    try {
293
        my $biblio_id = $c->validation->param('biblio_id');
292
        my $biblio_id = $c->param('biblio_id');
294
        my $biblio    = Koha::Biblios->find( $biblio_id );
293
        my $biblio    = Koha::Biblios->find( $biblio_id );
295
294
296
        unless ($biblio) {
295
        unless ($biblio) {
Lines 300-306 sub add_item { Link Here
300
            );
299
            );
301
        }
300
        }
302
301
303
        my $body = $c->validation->param('body');
302
        my $body = $c->req->json;
304
303
305
        $body->{biblio_id} = $biblio_id;
304
        $body->{biblio_id} = $biblio_id;
306
305
Lines 403-411 sub update_item { Link Here
403
    my $c = shift->openapi->valid_input or return;
402
    my $c = shift->openapi->valid_input or return;
404
403
405
    try {
404
    try {
406
        my $biblio_id = $c->validation->param('biblio_id');
405
        my $biblio_id = $c->param('biblio_id');
407
        my $item_id = $c->validation->param('item_id');
406
        my $item_id   = $c->param('item_id');
408
        my $biblio = Koha::Biblios->find({ biblionumber => $biblio_id });
407
        my $biblio    = Koha::Biblios->find( { biblionumber => $biblio_id } );
409
        unless ($biblio) {
408
        unless ($biblio) {
410
            return $c->render(
409
            return $c->render(
411
                status  => 404,
410
                status  => 404,
Lines 422-428 sub update_item { Link Here
422
            );
421
            );
423
        }
422
        }
424
423
425
        my $body = $c->validation->param('body');
424
        my $body = $c->req->json;
426
425
427
        $body->{biblio_id} = $biblio_id;
426
        $body->{biblio_id} = $biblio_id;
428
427
Lines 458-467 List Koha::Checkout objects Link Here
458
sub get_checkouts {
457
sub get_checkouts {
459
    my $c = shift->openapi->valid_input or return;
458
    my $c = shift->openapi->valid_input or return;
460
459
461
    my $checked_in = delete $c->validation->output->{checked_in};
460
    my $checked_in = $c->param('checked_in');
461
    $c->req->params->remove('checked_in');
462
462
463
    try {
463
    try {
464
        my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') );
464
        my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
465
465
466
        unless ($biblio) {
466
        unless ($biblio) {
467
            return $c->render(
467
            return $c->render(
Lines 495-502 used for building the dropdown selector Link Here
495
sub pickup_locations {
495
sub pickup_locations {
496
    my $c = shift->openapi->valid_input or return;
496
    my $c = shift->openapi->valid_input or return;
497
497
498
    my $biblio_id = $c->validation->param('biblio_id');
498
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
499
    my $biblio = Koha::Biblios->find( $biblio_id );
500
499
501
    unless ($biblio) {
500
    unless ($biblio) {
502
        return $c->render(
501
        return $c->render(
Lines 505-512 sub pickup_locations { Link Here
505
        );
504
        );
506
    }
505
    }
507
506
508
    my $patron_id = delete $c->validation->output->{patron_id};
507
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
509
    my $patron    = Koha::Patrons->find( $patron_id );
508
    $c->req->params->remove('patron_id');
510
509
511
    unless ($patron) {
510
    unless ($patron) {
512
        return $c->render(
511
        return $c->render(
Lines 562-568 access. Link Here
562
sub get_items_public {
561
sub get_items_public {
563
    my $c = shift->openapi->valid_input or return;
562
    my $c = shift->openapi->valid_input or return;
564
563
565
    my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, { prefetch => ['items'] } );
564
    my $biblio = Koha::Biblios->find(
565
        $c->param('biblio_id'),
566
        { prefetch => ['items'] }
567
    );
566
568
567
    unless ( $biblio ) {
569
    unless ( $biblio ) {
568
        return $c->render(
570
        return $c->render(
Lines 599-605 Set rating for the logged in user Link Here
599
sub set_rating {
601
sub set_rating {
600
    my $c = shift->openapi->valid_input or return;
602
    my $c = shift->openapi->valid_input or return;
601
603
602
    my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') );
604
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
603
605
604
    unless ($biblio) {
606
    unless ($biblio) {
605
        return $c->render(
607
        return $c->render(
Lines 619-625 sub set_rating { Link Here
619
        );
621
        );
620
    }
622
    }
621
623
622
    my $body   = $c->validation->param('body');
624
    my $body         = $c->req->json;
623
    my $rating_value = $body->{rating};
625
    my $rating_value = $body->{rating};
624
626
625
    return try {
627
    return try {
Lines 733-740 Controller function that handles modifying an biblio object Link Here
733
sub update {
735
sub update {
734
    my $c = shift->openapi->valid_input or return;
736
    my $c = shift->openapi->valid_input or return;
735
737
736
    my $biblio_id = $c->param('biblio_id');
738
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
737
    my $biblio    = Koha::Biblios->find($biblio_id);
738
739
739
    if ( ! defined $biblio ) {
740
    if ( ! defined $biblio ) {
740
        return $c->render(
741
        return $c->render(
Lines 776-786 sub update { Link Here
776
            );
777
            );
777
        }
778
        }
778
779
779
        ModBiblio( $record, $biblio_id, $frameworkcode );
780
        ModBiblio( $record, $biblio->id, $frameworkcode );
780
781
781
        $c->render(
782
        $c->render(
782
            status  => 200,
783
            status  => 200,
783
            openapi => { id => $biblio_id }
784
            openapi => { id => $biblio->id }
784
        );
785
        );
785
    }
786
    }
786
    catch {
787
    catch {
(-)a/Koha/REST/V1/Biblios/ItemGroups.pm (-11 / +11 lines)
Lines 42-50 Controller function that handles listing Koha::Biblio::ItemGroup objects Link Here
42
42
43
sub list {
43
sub list {
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
    my $biblio_id = $c->validation->param('biblio_id');
46
45
47
    my $biblio=Koha::Biblios->find( $biblio_id);
46
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
48
47
49
    return try {
48
    return try {
50
#my $item_groups_set = Koha::Biblio::ItemGroups->new;
49
#my $item_groups_set = Koha::Biblio::ItemGroups->new;
Lines 70-77 sub get { Link Here
70
    my $c = shift->openapi->valid_input or return;
69
    my $c = shift->openapi->valid_input or return;
71
70
72
    try {
71
    try {
73
        my $item_group_id = $c->validation->param('item_group_id');
72
        my $item_group_id = $c->param('item_group_id');
74
        my $biblio_id = $c->validation->param('biblio_id');
73
        my $biblio_id     = $c->param('biblio_id');
75
74
76
        my $item_group = $c->objects->find( Koha::Biblio::ItemGroups->new, $item_group_id );
75
        my $item_group = $c->objects->find( Koha::Biblio::ItemGroups->new, $item_group_id );
77
76
Lines 154-161 sub update { Link Here
154
    my $c = shift->openapi->valid_input or return;
153
    my $c = shift->openapi->valid_input or return;
155
154
156
    return try {
155
    return try {
157
        my $item_group_id = $c->validation->param('item_group_id');
156
        my $item_group_id = $c->param('item_group_id');
158
        my $biblio_id     = $c->validation->param('biblio_id');
157
        my $biblio_id     = $c->param('biblio_id');
159
158
160
        my $item_group = Koha::Biblio::ItemGroups->find( $item_group_id );
159
        my $item_group = Koha::Biblio::ItemGroups->find( $item_group_id );
161
160
Lines 168-174 sub update { Link Here
168
            );
167
            );
169
        }
168
        }
170
169
171
        my $item_group_data = $c->validation->param('body');
170
        my $item_group_data = $c->req->json;
172
        $item_group->set_from_api( $item_group_data )->store->discard_changes();
171
        $item_group->set_from_api( $item_group_data )->store->discard_changes();
173
172
174
        return $c->render(
173
        return $c->render(
Lines 204-214 sub delete { Link Here
204
203
205
    my $c = shift->openapi->valid_input or return;
204
    my $c = shift->openapi->valid_input or return;
206
205
207
    my $item_group_id = $c->validation->param('item_group_id');
208
    my $biblio_id     = $c->validation->param('biblio_id');
209
210
    my $item_group = Koha::Biblio::ItemGroups->find(
206
    my $item_group = Koha::Biblio::ItemGroups->find(
211
        { item_group_id => $item_group_id, biblio_id => $biblio_id } );
207
        {
208
            item_group_id => $c->param('item_group_id'),
209
            biblio_id     => $c->param('biblio_id')
210
        }
211
    );
212
212
213
    if ( not defined $item_group ) {
213
    if ( not defined $item_group ) {
214
        return $c->render(
214
        return $c->render(
(-)a/Koha/REST/V1/Biblios/ItemGroups/Items.pm (-7 / +5 lines)
Lines 43-51 sub add { Link Here
43
43
44
    return try {
44
    return try {
45
45
46
        my $item_group = Koha::Biblio::ItemGroups->find(
46
        my $item_group = Koha::Biblio::ItemGroups->find( $c->param('item_group_id') );
47
            $c->validation->param('item_group_id')
48
        );
49
47
50
        unless ( $item_group ) {
48
        unless ( $item_group ) {
51
            return $c->render(
49
            return $c->render(
Lines 56-62 sub add { Link Here
56
            );
54
            );
57
        }
55
        }
58
56
59
        unless ( $item_group->biblio_id eq $c->validation->param('biblio_id') ) {
57
        unless ( $item_group->biblio_id eq $c->param('biblio_id') ) {
60
            return $c->render(
58
            return $c->render(
61
                status  => 409,
59
                status  => 409,
62
                openapi => {
60
                openapi => {
Lines 66-72 sub add { Link Here
66
        }
64
        }
67
65
68
        # All good, add the item
66
        # All good, add the item
69
        my $body    = $c->validation->param('body');
67
        my $body    = $c->req->json;
70
        my $item_id = $body->{item_id};
68
        my $item_id = $body->{item_id};
71
69
72
        $item_group->add_item({ item_id => $item_id });
70
        $item_group->add_item({ item_id => $item_id });
Lines 125-132 Controller function that handles unlinking an item from a Koha::Biblio::ItemGrou Link Here
125
sub delete {
123
sub delete {
126
    my $c = shift->openapi->valid_input or return;
124
    my $c = shift->openapi->valid_input or return;
127
125
128
    my $item_group_id = $c->validation->param('item_group_id');
126
    my $item_group_id = $c->param('item_group_id');
129
    my $item_id       = $c->validation->param('item_id');
127
    my $item_id       = $c->param('item_id');
130
128
131
    my $item_link = Koha::Biblio::ItemGroup::Items->find(
129
    my $item_link = Koha::Biblio::ItemGroup::Items->find(
132
        {
130
        {
(-)a/Koha/REST/V1/CashRegisters/Cashups.pm (-9 / +3 lines)
Lines 40-50 Controller function that handles retrieving a cash registers cashup actions Link Here
40
sub list {
40
sub list {
41
    my $c = shift->openapi->valid_input or return;
41
    my $c = shift->openapi->valid_input or return;
42
42
43
    my $register = Koha::Cash::Registers->find(
43
    my $register = Koha::Cash::Registers->find( $c->param('cash_register_id') );
44
        {
45
            id => $c->validation->param('cash_register_id')
46
        }
47
    );
48
44
49
    unless ($register) {
45
    unless ($register) {
50
        return $c->render(
46
        return $c->render(
Lines 56-63 sub list { Link Here
56
    }
52
    }
57
53
58
    return try {
54
    return try {
59
        my $cashups_rs = $register->cashups;
55
        my $cashups = $c->objects->search( $register->cashups );
60
        my $cashups    = $c->objects->search($cashups_rs);
61
        return $c->render( status => 200, openapi => $cashups );
56
        return $c->render( status => 200, openapi => $cashups );
62
    }
57
    }
63
    catch {
58
    catch {
Lines 75-82 sub get { Link Here
75
    my $c = shift->openapi->valid_input or return;
70
    my $c = shift->openapi->valid_input or return;
76
71
77
    return try {
72
    return try {
78
        my $cashup = Koha::Cash::Register::Cashups->find(
73
        my $cashup = Koha::Cash::Register::Cashups->find( $c->param('cashup_id') );
79
            $c->validation->param('cashup_id') );
80
        unless ($cashup) {
74
        unless ($cashup) {
81
            return $c->render(
75
            return $c->render(
82
                status  => 404,
76
                status  => 404,
(-)a/Koha/REST/V1/Checkouts.pm (-6 / +7 lines)
Lines 46-52 List Koha::Checkout objects Link Here
46
sub list {
46
sub list {
47
    my $c = shift->openapi->valid_input or return;
47
    my $c = shift->openapi->valid_input or return;
48
48
49
    my $checked_in = delete $c->validation->output->{checked_in};
49
    my $checked_in = $c->param('checked_in');
50
    $c->req->params->remove('checked_in');
50
51
51
    try {
52
    try {
52
        my $checkouts_set;
53
        my $checkouts_set;
Lines 77-83 get one checkout Link Here
77
sub get {
78
sub get {
78
    my $c = shift->openapi->valid_input or return;
79
    my $c = shift->openapi->valid_input or return;
79
80
80
    my $checkout_id = $c->validation->param('checkout_id');
81
    my $checkout_id = $c->param('checkout_id');
81
    my $checkout = Koha::Checkouts->find( $checkout_id );
82
    my $checkout = Koha::Checkouts->find( $checkout_id );
82
    $checkout = Koha::Old::Checkouts->find( $checkout_id )
83
    $checkout = Koha::Old::Checkouts->find( $checkout_id )
83
        unless ($checkout);
84
        unless ($checkout);
Lines 293-299 sub get_renewals { Link Here
293
    my $c = shift->openapi->valid_input or return;
294
    my $c = shift->openapi->valid_input or return;
294
295
295
    try {
296
    try {
296
        my $checkout_id = $c->validation->param('checkout_id');
297
        my $checkout_id = $c->param('checkout_id');
297
        my $checkout    = Koha::Checkouts->find($checkout_id);
298
        my $checkout    = Koha::Checkouts->find($checkout_id);
298
        $checkout = Koha::Old::Checkouts->find($checkout_id)
299
        $checkout = Koha::Old::Checkouts->find($checkout_id)
299
          unless ($checkout);
300
          unless ($checkout);
Lines 328-335 Renew a checkout Link Here
328
sub renew {
329
sub renew {
329
    my $c = shift->openapi->valid_input or return;
330
    my $c = shift->openapi->valid_input or return;
330
331
331
    my $checkout_id = $c->validation->param('checkout_id');
332
    my $checkout_id = $c->param('checkout_id');
332
    my $seen = $c->validation->param('seen') || 1;
333
    my $seen = $c->param('seen') || 1;
333
    my $checkout = Koha::Checkouts->find( $checkout_id );
334
    my $checkout = Koha::Checkouts->find( $checkout_id );
334
335
335
    unless ($checkout) {
336
    unless ($checkout) {
Lines 379-385 Checks if the checkout could be renewed and return the related information. Link Here
379
sub allows_renewal {
380
sub allows_renewal {
380
    my $c = shift->openapi->valid_input or return;
381
    my $c = shift->openapi->valid_input or return;
381
382
382
    my $checkout_id = $c->validation->param('checkout_id');
383
    my $checkout_id = $c->param('checkout_id');
383
    my $checkout = Koha::Checkouts->find( $checkout_id );
384
    my $checkout = Koha::Checkouts->find( $checkout_id );
384
385
385
    unless ($checkout) {
386
    unless ($checkout) {
(-)a/Koha/REST/V1/Cities.pm (-7 / +6 lines)
Lines 35-42 sub list { Link Here
35
    my $c = shift->openapi->valid_input or return;
35
    my $c = shift->openapi->valid_input or return;
36
36
37
    return try {
37
    return try {
38
        my $cities_set = Koha::Cities->new;
38
        my $cities = $c->objects->search( Koha::Cities->new );
39
        my $cities = $c->objects->search( $cities_set );
40
        return $c->render( status => 200, openapi => $cities );
39
        return $c->render( status => 200, openapi => $cities );
41
    }
40
    }
42
    catch {
41
    catch {
Lines 53-59 sub get { Link Here
53
    my $c = shift->openapi->valid_input or return;
52
    my $c = shift->openapi->valid_input or return;
54
53
55
    return try {
54
    return try {
56
        my $city = Koha::Cities->find( $c->validation->param('city_id') );
55
        my $city = Koha::Cities->find( $c->param('city_id') );
57
        unless ($city) {
56
        unless ($city) {
58
            return $c->render( status  => 404,
57
            return $c->render( status  => 404,
59
                            openapi => { error => "City not found" } );
58
                            openapi => { error => "City not found" } );
Lines 74-80 sub add { Link Here
74
    my $c = shift->openapi->valid_input or return;
73
    my $c = shift->openapi->valid_input or return;
75
74
76
    return try {
75
    return try {
77
        my $city = Koha::City->new_from_api( $c->validation->param('body') );
76
        my $city = Koha::City->new_from_api( $c->req->json );
78
        $city->store;
77
        $city->store;
79
        $c->res->headers->location( $c->req->url->to_string . '/' . $city->cityid );
78
        $c->res->headers->location( $c->req->url->to_string . '/' . $city->cityid );
80
        return $c->render(
79
        return $c->render(
Lines 94-100 sub add { Link Here
94
sub update {
93
sub update {
95
    my $c = shift->openapi->valid_input or return;
94
    my $c = shift->openapi->valid_input or return;
96
95
97
    my $city = Koha::Cities->find( $c->validation->param('city_id') );
96
    my $city = Koha::Cities->find( $c->param('city_id') );
98
97
99
    if ( not defined $city ) {
98
    if ( not defined $city ) {
100
        return $c->render( status  => 404,
99
        return $c->render( status  => 404,
Lines 102-108 sub update { Link Here
102
    }
101
    }
103
102
104
    return try {
103
    return try {
105
        $city->set_from_api( $c->validation->param('body') );
104
        $city->set_from_api( $c->req->json );
106
        $city->store();
105
        $city->store();
107
        return $c->render( status => 200, openapi => $city->to_api );
106
        return $c->render( status => 200, openapi => $city->to_api );
108
    }
107
    }
Lines 118-124 sub update { Link Here
118
sub delete {
117
sub delete {
119
    my $c = shift->openapi->valid_input or return;
118
    my $c = shift->openapi->valid_input or return;
120
119
121
    my $city = Koha::Cities->find( $c->validation->param('city_id') );
120
    my $city = Koha::Cities->find( $c->param('city_id') );
122
    if ( not defined $city ) {
121
    if ( not defined $city ) {
123
        return $c->render( status  => 404,
122
        return $c->render( status  => 404,
124
                           openapi => { error => "Object not found" } );
123
                           openapi => { error => "Object not found" } );
(-)a/Koha/REST/V1/Clubs/Holds.pm (-2 / +2 lines)
Lines 44-51 sub add { Link Here
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    return try {
46
    return try {
47
        my $body    = $c->validation->param('body');
47
        my $body    = $c->req->json;
48
        my $club_id = $c->validation->param('club_id');
48
        my $club_id = $c->param('club_id');
49
49
50
        my $biblio;
50
        my $biblio;
51
51
(-)a/Koha/REST/V1/Config/SMTP/Servers.pm (-5 / +5 lines)
Lines 59-65 sub get { Link Here
59
    my $c = shift->openapi->valid_input or return;
59
    my $c = shift->openapi->valid_input or return;
60
60
61
    return try {
61
    return try {
62
        my $smtp_server = Koha::SMTP::Servers->find( $c->validation->param('smtp_server_id') );
62
        my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
63
63
64
        unless ($smtp_server) {
64
        unless ($smtp_server) {
65
            return $c->render(
65
            return $c->render(
Lines 93-99 sub add { Link Here
93
93
94
    return try {
94
    return try {
95
95
96
        my $smtp_server = Koha::SMTP::Server->new_from_api( $c->validation->param('body') );
96
        my $smtp_server = Koha::SMTP::Server->new_from_api( $c->req->json );
97
        $smtp_server->store->discard_changes;
97
        $smtp_server->store->discard_changes;
98
98
99
        $c->res->headers->location( $c->req->url->to_string . '/' . $smtp_server->id );
99
        $c->res->headers->location( $c->req->url->to_string . '/' . $smtp_server->id );
Lines 127-133 Controller method that handles updating a Koha::SMTP::Server object Link Here
127
sub update {
127
sub update {
128
    my $c = shift->openapi->valid_input or return;
128
    my $c = shift->openapi->valid_input or return;
129
129
130
    my $smtp_server = Koha::SMTP::Servers->find( $c->validation->param('smtp_server_id') );
130
    my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
131
131
132
    if ( not defined $smtp_server ) {
132
    if ( not defined $smtp_server ) {
133
        return $c->render(
133
        return $c->render(
Lines 139-145 sub update { Link Here
139
    }
139
    }
140
140
141
    return try {
141
    return try {
142
        $smtp_server->set_from_api( $c->validation->param('body') );
142
        $smtp_server->set_from_api( $c->req->json );
143
        $smtp_server->store->discard_changes;
143
        $smtp_server->store->discard_changes;
144
144
145
        return $c->render(
145
        return $c->render(
Lines 171-177 Controller method that handles deleting a Koha::SMTP::Server object Link Here
171
sub delete {
171
sub delete {
172
    my $c = shift->openapi->valid_input or return;
172
    my $c = shift->openapi->valid_input or return;
173
173
174
    my $smtp_server = Koha::SMTP::Servers->find( $c->validation->param('smtp_server_id') );
174
    my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
175
175
176
    if ( not defined $smtp_server ) {
176
    if ( not defined $smtp_server ) {
177
        return $c->render( status  => 404,
177
        return $c->render( status  => 404,
(-)a/Koha/REST/V1/Holds.pm (-26 / +20 lines)
Lines 45-52 sub list { Link Here
45
    my $c = shift->openapi->valid_input or return;
45
    my $c = shift->openapi->valid_input or return;
46
46
47
    return try {
47
    return try {
48
        my $holds_set = Koha::Holds->new;
48
        my $holds = $c->objects->search( Koha::Holds->new );
49
        my $holds     = $c->objects->search( $holds_set );
50
        return $c->render( status => 200, openapi => $holds );
49
        return $c->render( status => 200, openapi => $holds );
51
    }
50
    }
52
    catch {
51
    catch {
Lines 64-70 sub add { Link Here
64
    my $c = shift->openapi->valid_input or return;
63
    my $c = shift->openapi->valid_input or return;
65
64
66
    return try {
65
    return try {
67
        my $body = $c->validation->param('body');
66
        my $body = $c->req->json;
68
67
69
        my $biblio;
68
        my $biblio;
70
        my $item;
69
        my $item;
Lines 247-254 sub edit { Link Here
247
    my $c = shift->openapi->valid_input or return;
246
    my $c = shift->openapi->valid_input or return;
248
247
249
    return try {
248
    return try {
250
        my $hold_id = $c->validation->param('hold_id');
249
        my $hold = Koha::Holds->find( $c->param('hold_id') );
251
        my $hold = Koha::Holds->find( $hold_id );
252
250
253
        unless ($hold) {
251
        unless ($hold) {
254
            return $c->render(
252
            return $c->render(
Lines 260-266 sub edit { Link Here
260
        my $overrides = $c->stash('koha.overrides');
258
        my $overrides = $c->stash('koha.overrides');
261
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
259
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
262
260
263
        my $body = $c->validation->output->{body};
261
        my $body = $c->req->json;
264
262
265
        my $pickup_library_id = $body->{pickup_library_id};
263
        my $pickup_library_id = $body->{pickup_library_id};
266
264
Lines 283-289 sub edit { Link Here
283
        my $suspended_until = $body->{suspended_until} || $hold->suspend_until;
281
        my $suspended_until = $body->{suspended_until} || $hold->suspend_until;
284
282
285
        my $params = {
283
        my $params = {
286
            reserve_id    => $hold_id,
284
            reserve_id    => $hold->id,
287
            branchcode    => $pickup_library_id,
285
            branchcode    => $pickup_library_id,
288
            rank          => $priority,
286
            rank          => $priority,
289
            suspend_until => $suspended_until,
287
            suspend_until => $suspended_until,
Lines 312-319 Method that handles deleting a Koha::Hold object Link Here
312
sub delete {
310
sub delete {
313
    my $c = shift->openapi->valid_input or return;
311
    my $c = shift->openapi->valid_input or return;
314
312
315
    my $hold_id = $c->validation->param('hold_id');
313
    my $hold = Koha::Holds->find($c->param('hold_id'));
316
    my $hold    = Koha::Holds->find($hold_id);
317
314
318
    unless ($hold) {
315
    unless ($hold) {
319
        return $c->render( status => 404, openapi => { error => "Hold not found." } );
316
        return $c->render( status => 404, openapi => { error => "Hold not found." } );
Lines 341-349 Method that handles suspending a hold Link Here
341
sub suspend {
338
sub suspend {
342
    my $c = shift->openapi->valid_input or return;
339
    my $c = shift->openapi->valid_input or return;
343
340
344
    my $hold_id  = $c->validation->param('hold_id');
341
    my $hold = Koha::Holds->find( $c->param('hold_id') );
345
    my $hold     = Koha::Holds->find($hold_id);
342
    my $body = $c->req->json;
346
    my $body     = $c->req->json;
343
347
    my $end_date = ($body) ? $body->{end_date} : undef;
344
    my $end_date = ($body) ? $body->{end_date} : undef;
348
345
349
    unless ($hold) {
346
    unless ($hold) {
Lines 381-389 Method that handles resuming a hold Link Here
381
sub resume {
378
sub resume {
382
    my $c = shift->openapi->valid_input or return;
379
    my $c = shift->openapi->valid_input or return;
383
380
384
    my $hold_id = $c->validation->param('hold_id');
381
    my $hold = Koha::Holds->find($c->param('hold_id'));
385
    my $hold    = Koha::Holds->find($hold_id);
382
    my $body = $c->req->json;
386
    my $body    = $c->req->json;
387
383
388
    unless ($hold) {
384
    unless ($hold) {
389
        return $c->render( status => 404, openapi => { error => 'Hold not found.' } );
385
        return $c->render( status => 404, openapi => { error => 'Hold not found.' } );
Lines 407-414 Method that handles modifying a Koha::Hold object Link Here
407
sub update_priority {
403
sub update_priority {
408
    my $c = shift->openapi->valid_input or return;
404
    my $c = shift->openapi->valid_input or return;
409
405
410
    my $hold_id = $c->validation->param('hold_id');
406
    my $hold = Koha::Holds->find($c->param('hold_id'));
411
    my $hold = Koha::Holds->find($hold_id);
412
407
413
    unless ($hold) {
408
    unless ($hold) {
414
        return $c->render(
409
        return $c->render(
Lines 421-427 sub update_priority { Link Here
421
        my $priority = $c->req->json;
416
        my $priority = $c->req->json;
422
        C4::Reserves::_FixPriority(
417
        C4::Reserves::_FixPriority(
423
            {
418
            {
424
                reserve_id => $hold_id,
419
                reserve_id => $hold->id,
425
                rank       => $priority
420
                rank       => $priority
426
            }
421
            }
427
        );
422
        );
Lines 443-450 used for building the dropdown selector Link Here
443
sub pickup_locations {
438
sub pickup_locations {
444
    my $c = shift->openapi->valid_input or return;
439
    my $c = shift->openapi->valid_input or return;
445
440
446
    my $hold_id = $c->validation->param('hold_id');
441
    my $hold = Koha::Holds->find( $c->param('hold_id'), { prefetch => [ 'patron' ] } );
447
    my $hold = Koha::Holds->find( $hold_id, { prefetch => [ 'patron' ] } );
448
442
449
    unless ($hold) {
443
    unless ($hold) {
450
        return $c->render(
444
        return $c->render(
Lines 509-519 Method that handles modifying the pickup location of a Koha::Hold object Link Here
509
sub update_pickup_location {
503
sub update_pickup_location {
510
    my $c = shift->openapi->valid_input or return;
504
    my $c = shift->openapi->valid_input or return;
511
505
512
    my $hold_id = $c->validation->param('hold_id');
506
    my $hold = Koha::Holds->find($c->param('hold_id'));
513
    my $body    = $c->validation->param('body');
514
    my $pickup_library_id = $body->{pickup_library_id};
515
516
    my $hold = Koha::Holds->find($hold_id);
517
507
518
    unless ($hold) {
508
    unless ($hold) {
519
        return $c->render(
509
        return $c->render(
Lines 522-529 sub update_pickup_location { Link Here
522
        );
512
        );
523
    }
513
    }
524
514
515
525
    return try {
516
    return try {
526
517
518
        my $body = $c->req->json;
519
520
        my $pickup_library_id = $body->{pickup_library_id};
521
527
        my $overrides    = $c->stash('koha.overrides');
522
        my $overrides    = $c->stash('koha.overrides');
528
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
523
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
529
524
Lines 556-560 sub update_pickup_location { Link Here
556
    };
551
    };
557
}
552
}
558
553
559
560
1;
554
1;
(-)a/Koha/REST/V1/Illbackends.pm (-1 / +1 lines)
Lines 62-68 Get one backend Link Here
62
sub get {
62
sub get {
63
    my $c = shift->openapi->valid_input;
63
    my $c = shift->openapi->valid_input;
64
64
65
    my $backend_id = $c->validation->param('ill_backend_id');
65
    my $backend_id = $c->param('ill_backend_id');
66
66
67
    return try {
67
    return try {
68
68
(-)a/Koha/REST/V1/ImportBatchProfiles.pm (-14 / +11 lines)
Lines 44-53 sub list { Link Here
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    return try {
46
    return try {
47
        my $profiles_set = Koha::ImportBatchProfiles->new;
47
        my $profiles = $c->objects->search( Koha::ImportBatchProfiles->new );
48
        my $profiles = $c->objects->search( $profiles_set );
49
        return $c->render(
48
        return $c->render(
50
            status => 200,
49
            status  => 200,
51
            openapi => $profiles
50
            openapi => $profiles
52
        );
51
        );
53
    }
52
    }
Lines 65-71 Method that handles adding a new Koha::ImportBatchProfile object Link Here
65
sub add {
64
sub add {
66
    my $c = shift->openapi->valid_input or return;
65
    my $c = shift->openapi->valid_input or return;
67
66
68
    my $body = $c->validation->param('body');
67
    my $body = $c->req->json;
69
68
70
    return try {
69
    return try {
71
        my $profile = Koha::ImportBatchProfile->new_from_api( $body )->store;
70
        my $profile = Koha::ImportBatchProfile->new_from_api( $body )->store;
Lines 89-107 sub edit { Link Here
89
    my $c = shift->openapi->valid_input or return;
88
    my $c = shift->openapi->valid_input or return;
90
89
91
    return try {
90
    return try {
92
        my $profile_id = $c->validation->param('import_batch_profile_id');
91
        my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
93
        my $profile = Koha::ImportBatchProfiles->find( $profile_id );
94
        unless ($profile) {
92
        unless ($profile) {
95
            return $c->render( status  => 404,
93
            return $c->render(
96
                            openapi => {error => "Import batch profile not found"} );
94
                status  => 404,
95
                openapi => {error => "Import batch profile not found"}
96
            );
97
        }
97
        }
98
98
99
        my $body = $c->req->json;
99
        $profile->set_from_api($c->req->json)->store;
100
101
        $profile->set_from_api($body)->store;
102
100
103
        return $c->render(
101
        return $c->render(
104
            status => 200,
102
            status  => 200,
105
            openapi => $profile->to_api
103
            openapi => $profile->to_api
106
        );
104
        );
107
    }
105
    }
Lines 119-126 Method that handles deleting a Koha::ImportBatchProfile object Link Here
119
sub delete {
117
sub delete {
120
    my $c = shift->openapi->valid_input or return;
118
    my $c = shift->openapi->valid_input or return;
121
119
122
    my $profile_id = $c->validation->param('import_batch_profile_id');
120
    my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
123
    my $profile = Koha::ImportBatchProfiles->find( $profile_id );
124
121
125
    unless ($profile) {
122
    unless ($profile) {
126
        return $c->render( status  => 404,
123
        return $c->render( status  => 404,
(-)a/Koha/REST/V1/ImportRecordMatches.pm (-4 / +3 lines)
Lines 40-48 DELETE /api/v1/import_batches/{import_batch_id}/records/{import_record_id}/match Link Here
40
sub unset_chosen {
40
sub unset_chosen {
41
    my $c = shift->openapi->valid_input or return;
41
    my $c = shift->openapi->valid_input or return;
42
42
43
    my $import_record_id = $c->validation->param('import_record_id');
44
    my $matches = Koha::Import::Record::Matches->search({
43
    my $matches = Koha::Import::Record::Matches->search({
45
        import_record_id => $import_record_id,
44
        import_record_id => $c->param('import_record_id'),
46
    });
45
    });
47
    unless ($matches) {
46
    unless ($matches) {
48
        return $c->render(
47
        return $c->render(
Lines 72-79 Body should contain the condidate_match_id to chose Link Here
72
sub set_chosen {
71
sub set_chosen {
73
    my $c = shift->openapi->valid_input or return;
72
    my $c = shift->openapi->valid_input or return;
74
73
75
    my $import_record_id = $c->validation->param('import_record_id');
74
    my $import_record_id = $c->param('import_record_id');
76
    my $body    = $c->validation->param('body');
75
    my $body = $c->req->json;
77
    my $candidate_match_id = $body->{'candidate_match_id'};
76
    my $candidate_match_id = $body->{'candidate_match_id'};
78
77
79
    my $match = Koha::Import::Record::Matches->find({
78
    my $match = Koha::Import::Record::Matches->find({
(-)a/Koha/REST/V1/Items.pm (-10 / +13 lines)
Lines 95-101 sub get { Link Here
95
95
96
    try {
96
    try {
97
        my $items_rs = Koha::Items->new;
97
        my $items_rs = Koha::Items->new;
98
        my $item = $c->objects->find($items_rs, $c->validation->param('item_id'));
98
        my $item = $c->objects->find($items_rs, $c->param('item_id'));
99
        unless ( $item ) {
99
        unless ( $item ) {
100
            return $c->render(
100
            return $c->render(
101
                status => 404,
101
                status => 404,
Lines 119-125 sub delete { Link Here
119
    my $c = shift->openapi->valid_input or return;
119
    my $c = shift->openapi->valid_input or return;
120
120
121
    return try {
121
    return try {
122
        my $item = Koha::Items->find($c->validation->param('item_id'));
122
        my $item = Koha::Items->find($c->param('item_id'));
123
        unless ( $item ) {
123
        unless ( $item ) {
124
            return $c->render(
124
            return $c->render(
125
                status => 404,
125
                status => 404,
Lines 184-190 used for building the dropdown selector Link Here
184
sub pickup_locations {
184
sub pickup_locations {
185
    my $c = shift->openapi->valid_input or return;
185
    my $c = shift->openapi->valid_input or return;
186
186
187
    my $item_id = $c->validation->param('item_id');
187
    my $item_id = $c->param('item_id');
188
    my $item = Koha::Items->find( $item_id );
188
    my $item = Koha::Items->find( $item_id );
189
189
190
    unless ($item) {
190
    unless ($item) {
Lines 194-202 sub pickup_locations { Link Here
194
        );
194
        );
195
    }
195
    }
196
196
197
    my $patron_id = delete $c->validation->output->{patron_id};
197
    my $patron_id = $c->param('patron_id');
198
    my $patron    = Koha::Patrons->find( $patron_id );
198
    my $patron    = Koha::Patrons->find( $patron_id );
199
199
200
    $c->req->params->remove('patron_id');
201
200
    unless ($patron) {
202
    unless ($patron) {
201
        return $c->render(
203
        return $c->render(
202
            status  => 400,
204
            status  => 400,
Lines 250-256 Controller function that handles bundled_items Koha::Item objects Link Here
250
sub bundled_items {
252
sub bundled_items {
251
    my $c = shift->openapi->valid_input or return;
253
    my $c = shift->openapi->valid_input or return;
252
254
253
    my $item_id = $c->validation->param('item_id');
255
    my $item_id = $c->param('item_id');
254
    my $item = Koha::Items->find( $item_id );
256
    my $item = Koha::Items->find( $item_id );
255
257
256
    unless ($item) {
258
    unless ($item) {
Lines 282-288 Controller function that handles adding items to this bundle Link Here
282
sub add_to_bundle {
284
sub add_to_bundle {
283
    my $c = shift->openapi->valid_input or return;
285
    my $c = shift->openapi->valid_input or return;
284
286
285
    my $item_id = $c->validation->param('item_id');
287
    my $item_id = $c->param('item_id');
286
    my $item = Koha::Items->find( $item_id );
288
    my $item = Koha::Items->find( $item_id );
287
289
288
    unless ($item) {
290
    unless ($item) {
Lines 292-298 sub add_to_bundle { Link Here
292
        );
294
        );
293
    }
295
    }
294
296
295
    my $bundle_item_id = $c->validation->param('body')->{'external_id'};
297
    my $body = $c->req->json;
298
299
    my $bundle_item_id = $body->{'external_id'};
296
    $bundle_item_id = barcodedecode($bundle_item_id);
300
    $bundle_item_id = barcodedecode($bundle_item_id);
297
    my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
301
    my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
298
302
Lines 304-310 sub add_to_bundle { Link Here
304
    }
308
    }
305
309
306
    return try {
310
    return try {
307
        my $body = $c->validation->param('body');
308
        my $options = {
311
        my $options = {
309
            force_checkin => $body->{force_checkin},
312
            force_checkin => $body->{force_checkin},
310
            ignore_holds => $body->{ignore_holds},
313
            ignore_holds => $body->{ignore_holds},
Lines 386-392 Controller function that handles removing items from this bundle Link Here
386
sub remove_from_bundle {
389
sub remove_from_bundle {
387
    my $c = shift->openapi->valid_input or return;
390
    my $c = shift->openapi->valid_input or return;
388
391
389
    my $item_id = $c->validation->param('item_id');
392
    my $item_id = $c->param('item_id');
390
    my $item = Koha::Items->find( $item_id );
393
    my $item = Koha::Items->find( $item_id );
391
394
392
    unless ($item) {
395
    unless ($item) {
Lines 396-402 sub remove_from_bundle { Link Here
396
        );
399
        );
397
    }
400
    }
398
401
399
    my $bundle_item_id = $c->validation->param('bundled_item_id');
402
    my $bundle_item_id = $c->param('bundled_item_id');
400
    $bundle_item_id = barcodedecode($bundle_item_id);
403
    $bundle_item_id = barcodedecode($bundle_item_id);
401
    my $bundle_item = Koha::Items->find( { itemnumber => $bundle_item_id } );
404
    my $bundle_item = Koha::Items->find( { itemnumber => $bundle_item_id } );
402
405
(-)a/Koha/REST/V1/Libraries.pm (-9 / +9 lines)
Lines 44-51 sub list { Link Here
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    return try {
46
    return try {
47
        my $libraries_set = Koha::Libraries->new;
47
        my $libraries = $c->objects->search( Koha::Libraries->new );
48
        my $libraries     = $c->objects->search( $libraries_set );
49
        return $c->render( status => 200, openapi => $libraries );
48
        return $c->render( status => 200, openapi => $libraries );
50
    }
49
    }
51
    catch {
50
    catch {
Lines 63-74 sub get { Link Here
63
    my $c = shift->openapi->valid_input or return;
62
    my $c = shift->openapi->valid_input or return;
64
63
65
    return try {
64
    return try {
66
        my $library_id = $c->validation->param('library_id');
65
        my $library = Koha::Libraries->find( $c->param('library_id') );
67
        my $library = Koha::Libraries->find( $library_id );
68
66
69
        unless ($library) {
67
        unless ($library) {
70
            return $c->render( status  => 404,
68
            return $c->render(
71
                            openapi => { error => "Library not found" } );
69
                status  => 404,
70
                openapi => { error => "Library not found" }
71
            );
72
        }
72
        }
73
73
74
        return $c->render(
74
        return $c->render(
Lines 91-97 sub add { Link Here
91
    my $c = shift->openapi->valid_input or return;
91
    my $c = shift->openapi->valid_input or return;
92
92
93
    return try {
93
    return try {
94
        my $library = Koha::Library->new_from_api( $c->validation->param('body') );
94
        my $library = Koha::Library->new_from_api( $c->req->json );
95
        $library->store;
95
        $library->store;
96
        $c->res->headers->location( $c->req->url->to_string . '/' . $library->branchcode );
96
        $c->res->headers->location( $c->req->url->to_string . '/' . $library->branchcode );
97
97
Lines 121-127 Controller function that handles updating a Koha::Library object Link Here
121
sub update {
121
sub update {
122
    my $c = shift->openapi->valid_input or return;
122
    my $c = shift->openapi->valid_input or return;
123
123
124
    my $library = Koha::Libraries->find( $c->validation->param('library_id') );
124
    my $library = Koha::Libraries->find( $c->param('library_id') );
125
125
126
    if ( not defined $library ) {
126
    if ( not defined $library ) {
127
        return $c->render(
127
        return $c->render(
Lines 154-160 sub delete { Link Here
154
154
155
    my $c = shift->openapi->valid_input or return;
155
    my $c = shift->openapi->valid_input or return;
156
156
157
    my $library = Koha::Libraries->find( $c->validation->param( 'library_id' ) );
157
    my $library = Koha::Libraries->find( $c->param( 'library_id' ) );
158
158
159
    if ( not defined $library ) {
159
    if ( not defined $library ) {
160
        return $c->render( status => 404, openapi => { error => "Library not found" } );
160
        return $c->render( status => 404, openapi => { error => "Library not found" } );
(-)a/Koha/REST/V1/OAuth.pm (-3 / +3 lines)
Lines 49-55 sub token { Link Here
49
        return $c->render( status => 400, openapi => { error => 'Unimplemented grant type' } );
49
        return $c->render( status => 400, openapi => { error => 'Unimplemented grant type' } );
50
    }
50
    }
51
51
52
    my $grant_type = $c->validation->param('grant_type');
52
    my $grant_type = $c->param('grant_type');
53
    unless ( $grant_type eq 'client_credentials' and C4::Context->preference('RESTOAuth2ClientCredentials') ) {
53
    unless ( $grant_type eq 'client_credentials' and C4::Context->preference('RESTOAuth2ClientCredentials') ) {
54
        return $c->render(status => 400, openapi => {error => 'Unimplemented grant type'});
54
        return $c->render(status => 400, openapi => {error => 'Unimplemented grant type'});
55
    }
55
    }
Lines 70-77 sub token { Link Here
70
        ( $client_id, $client_secret ) = split( /:/, $decoded_credentials, 2 );
70
        ( $client_id, $client_secret ) = split( /:/, $decoded_credentials, 2 );
71
    }
71
    }
72
    else {
72
    else {
73
        $client_id = $c->validation->param('client_id');
73
        $client_id = $c->param('client_id');
74
        $client_secret = $c->validation->param('client_secret');
74
        $client_secret = $c->param('client_secret');
75
    }
75
    }
76
76
77
    my $cb = "${grant_type}_grant";
77
    my $cb = "${grant_type}_grant";
(-)a/Koha/REST/V1/Patrons.pm (-8 / +8 lines)
Lines 47-53 sub list { Link Here
47
    return try {
47
    return try {
48
48
49
        my $query = {};
49
        my $query = {};
50
        my $restricted = delete $c->validation->output->{restricted};
50
        my $restricted = $c->param('restricted');
51
        $c->req->params->remove('restricted');
51
        $query->{debarred} = { '!=' => undef }
52
        $query->{debarred} = { '!=' => undef }
52
            if $restricted;
53
            if $restricted;
53
54
Lines 74-80 sub get { Link Here
74
    my $c = shift->openapi->valid_input or return;
75
    my $c = shift->openapi->valid_input or return;
75
76
76
    return try {
77
    return try {
77
        my $patron_id = $c->validation->param('patron_id');
78
        my $patron_id = $c->param('patron_id');
78
        my $patron    = $c->objects->find( Koha::Patrons->search_limited, $patron_id );
79
        my $patron    = $c->objects->find( Koha::Patrons->search_limited, $patron_id );
79
80
80
        unless ($patron) {
81
        unless ($patron) {
Lines 108-114 sub add { Link Here
108
        Koha::Database->new->schema->txn_do(
109
        Koha::Database->new->schema->txn_do(
109
            sub {
110
            sub {
110
111
111
                my $body = $c->validation->param('body');
112
                my $body = $c->req->json;
112
113
113
                my $extended_attributes = delete $body->{extended_attributes} // [];
114
                my $extended_attributes = delete $body->{extended_attributes} // [];
114
115
Lines 225-232 Controller function that handles updating a Koha::Patron object Link Here
225
sub update {
226
sub update {
226
    my $c = shift->openapi->valid_input or return;
227
    my $c = shift->openapi->valid_input or return;
227
228
228
    my $patron_id = $c->validation->param('patron_id');
229
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
229
    my $patron    = Koha::Patrons->find( $patron_id );
230
230
231
    unless ($patron) {
231
    unless ($patron) {
232
         return $c->render(
232
         return $c->render(
Lines 236-242 sub update { Link Here
236
     }
236
     }
237
237
238
    return try {
238
    return try {
239
        my $body = $c->validation->param('body');
239
        my $body = $c->req->json;
240
        my $user = $c->stash('koha.user');
240
        my $user = $c->stash('koha.user');
241
241
242
        if (
242
        if (
Lines 269-275 sub update { Link Here
269
            }
269
            }
270
        }
270
        }
271
271
272
        $patron->set_from_api($c->validation->param('body'))->store;
272
        $patron->set_from_api($body)->store;
273
        $patron->discard_changes;
273
        $patron->discard_changes;
274
        return $c->render( status => 200, openapi => $patron->to_api );
274
        return $c->render( status => 200, openapi => $patron->to_api );
275
    }
275
    }
Lines 341-347 Controller function that handles deleting a Koha::Patron object Link Here
341
sub delete {
341
sub delete {
342
    my $c = shift->openapi->valid_input or return;
342
    my $c = shift->openapi->valid_input or return;
343
343
344
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
344
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
345
345
346
    unless ( $patron ) {
346
    unless ( $patron ) {
347
        return $c->render(
347
        return $c->render(
(-)a/Koha/REST/V1/Patrons/Account.pm (-21 / +10 lines)
Lines 40-47 Controller function that handles retrieving a patron's account balance Link Here
40
sub get {
40
sub get {
41
    my $c = shift->openapi->valid_input or return;
41
    my $c = shift->openapi->valid_input or return;
42
42
43
    my $patron_id = $c->validation->param('patron_id');
43
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
44
    my $patron    = Koha::Patrons->find($patron_id);
45
44
46
    unless ($patron) {
45
    unless ($patron) {
47
        return $c->render(
46
        return $c->render(
Lines 84-91 sub get { Link Here
84
sub list_credits {
83
sub list_credits {
85
    my $c = shift->openapi->valid_input or return;
84
    my $c = shift->openapi->valid_input or return;
86
85
87
    my $patron_id = $c->validation->param('patron_id');
86
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
88
    my $patron    = Koha::Patrons->find($patron_id);
89
87
90
    unless ($patron) {
88
    unless ($patron) {
91
        return $c->render(
89
        return $c->render(
Lines 95-104 sub list_credits { Link Here
95
    }
93
    }
96
94
97
    return try {
95
    return try {
98
        my $account = $patron->account;
96
        my $credits = $c->objects->search( $patron->account->credits );
99
100
        my $credits_set = $account->credits;
101
        my $credits     = $c->objects->search($credits_set);
102
        return $c->render( status => 200, openapi => $credits );
97
        return $c->render( status => 200, openapi => $credits );
103
    }
98
    }
104
    catch {
99
    catch {
Lines 115-123 Controller function that handles adding a credit to a patron's account Link Here
115
sub add_credit {
110
sub add_credit {
116
    my $c = shift->openapi->valid_input or return;
111
    my $c = shift->openapi->valid_input or return;
117
112
118
    my $patron_id = $c->validation->param('patron_id');
113
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
119
    my $patron    = Koha::Patrons->find($patron_id);
114
    my $user   = $c->stash('koha.user');
120
    my $user      = $c->stash('koha.user');
121
115
122
    unless ($patron) {
116
    unless ($patron) {
123
        return $c->render(
117
        return $c->render(
Lines 127-133 sub add_credit { Link Here
127
    }
121
    }
128
122
129
    my $account = $patron->account;
123
    my $account = $patron->account;
130
    my $body    = $c->validation->param('body');
124
    my $body    = $c->req->json;
131
125
132
    return try {
126
    return try {
133
        my $credit_type =
127
        my $credit_type =
Lines 203-210 sub add_credit { Link Here
203
sub list_debits {
197
sub list_debits {
204
    my $c = shift->openapi->valid_input or return;
198
    my $c = shift->openapi->valid_input or return;
205
199
206
    my $patron_id = $c->validation->param('patron_id');
200
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
207
    my $patron    = Koha::Patrons->find($patron_id);
208
201
209
    unless ($patron) {
202
    unless ($patron) {
210
        return $c->render(
203
        return $c->render(
Lines 214-223 sub list_debits { Link Here
214
    }
207
    }
215
208
216
    return try {
209
    return try {
217
        my $account = $patron->account;
210
        my $debits = $c->objects->search( $patron->account->debits );
218
219
        my $debits_set = $account->debits;
220
        my $debits     = $c->objects->search($debits_set);
221
        return $c->render( status => 200, openapi => $debits );
211
        return $c->render( status => 200, openapi => $debits );
222
    }
212
    }
223
    catch {
213
    catch {
Lines 232-239 sub list_debits { Link Here
232
sub add_debit {
222
sub add_debit {
233
    my $c = shift->openapi->valid_input or return;
223
    my $c = shift->openapi->valid_input or return;
234
224
235
    my $patron_id = $c->validation->param('patron_id');
225
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
236
    my $patron    = Koha::Patrons->find($patron_id);
237
226
238
    unless ($patron) {
227
    unless ($patron) {
239
        return $c->render(
228
        return $c->render(
Lines 244-250 sub add_debit { Link Here
244
233
245
    return try {
234
    return try {
246
        my $data =
235
        my $data =
247
          Koha::Account::Debit->new_from_api( $c->validation->param('body') )
236
          Koha::Account::Debit->new_from_api( $c->req->json )
248
          ->unblessed;
237
          ->unblessed;
249
238
250
        $data->{library_id}       = delete $data->{branchcode};
239
        $data->{library_id}       = delete $data->{branchcode};
(-)a/Koha/REST/V1/Patrons/Attributes.pm (-12 / +11 lines)
Lines 43-49 to a given patron. Link Here
43
sub list_patron_attributes {
43
sub list_patron_attributes {
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
46
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
47
47
48
    unless ($patron) {
48
    unless ($patron) {
49
        return $c->render(
49
        return $c->render(
Lines 56-63 sub list_patron_attributes { Link Here
56
56
57
    return try {
57
    return try {
58
58
59
        my $attributes_rs = $patron->extended_attributes;
59
        my $attributes = $c->objects->search( $patron->extended_attributes );
60
        my $attributes    = $c->objects->search($attributes_rs);
61
60
62
        return $c->render(
61
        return $c->render(
63
            status  => 200,
62
            status  => 200,
Lines 78-84 Controller method that handles adding a Koha::Patron::Attribute to a given patro Link Here
78
sub add {
77
sub add {
79
    my $c = shift->openapi->valid_input or return;
78
    my $c = shift->openapi->valid_input or return;
80
79
81
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
80
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
82
81
83
    unless ($patron) {
82
    unless ($patron) {
84
        return $c->render(
83
        return $c->render(
Lines 93-99 sub add { Link Here
93
92
94
        my $attribute = $patron->add_extended_attribute(
93
        my $attribute = $patron->add_extended_attribute(
95
            Koha::Patron::Attribute->new_from_api( # new_from_api takes care of mapping attributes
94
            Koha::Patron::Attribute->new_from_api( # new_from_api takes care of mapping attributes
96
                $c->validation->param('body')
95
                $c->req->json
97
            )->unblessed
96
            )->unblessed
98
        );
97
        );
99
98
Lines 150-156 Controller method that handles overwriting extended attributes for a given patro Link Here
150
sub overwrite {
149
sub overwrite {
151
    my $c = shift->openapi->valid_input or return;
150
    my $c = shift->openapi->valid_input or return;
152
151
153
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
152
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
154
153
155
    unless ($patron) {
154
    unless ($patron) {
156
        return $c->render(
155
        return $c->render(
Lines 163-169 sub overwrite { Link Here
163
162
164
    return try {
163
    return try {
165
164
166
        my $body = $c->validation->every_param('body');
165
        my $body = $c->req->json;
167
166
168
        my @attrs;
167
        my @attrs;
169
168
Lines 228-234 Controller method that handles updating a single extended patron attribute. Link Here
228
sub update {
227
sub update {
229
    my $c = shift->openapi->valid_input or return;
228
    my $c = shift->openapi->valid_input or return;
230
229
231
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
230
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
232
231
233
    unless ($patron) {
232
    unless ($patron) {
234
        return $c->render(
233
        return $c->render(
Lines 241-247 sub update { Link Here
241
240
242
    return try {
241
    return try {
243
        my $attribute = $patron->extended_attributes->find(
242
        my $attribute = $patron->extended_attributes->find(
244
            $c->validation->param('extended_attribute_id') );
243
            $c->param('extended_attribute_id') );
245
244
246
        unless ($attribute) {
245
        unless ($attribute) {
247
            return $c->render(
246
            return $c->render(
Lines 252-258 sub update { Link Here
252
            );
251
            );
253
        }
252
        }
254
253
255
        $attribute->set_from_api( $c->validation->param('body') )->store;
254
        $attribute->set_from_api( $c->req->json )->store;
256
        $attribute->discard_changes;
255
        $attribute->discard_changes;
257
256
258
        return $c->render(
257
        return $c->render(
Lines 302-308 Controller method that handles removing an extended patron attribute. Link Here
302
sub delete {
301
sub delete {
303
    my $c = shift->openapi->valid_input or return;
302
    my $c = shift->openapi->valid_input or return;
304
303
305
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
304
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
306
305
307
    unless ($patron) {
306
    unless ($patron) {
308
        return $c->render(
307
        return $c->render(
Lines 316-322 sub delete { Link Here
316
    return try {
315
    return try {
317
316
318
        my $attribute = $patron->extended_attributes->find(
317
        my $attribute = $patron->extended_attributes->find(
319
            $c->validation->param('extended_attribute_id') );
318
            $c->param('extended_attribute_id') );
320
319
321
        unless ($attribute) {
320
        unless ($attribute) {
322
            return $c->render(
321
            return $c->render(
(-)a/Koha/REST/V1/Patrons/Holds.pm (-3 / +2 lines)
Lines 38-44 Controller function that handles listing Koha::Hold objects for the requested pa Link Here
38
sub list {
38
sub list {
39
    my $c = shift->openapi->valid_input or return;
39
    my $c = shift->openapi->valid_input or return;
40
40
41
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
42
42
43
    unless ( $patron ) {
43
    unless ( $patron ) {
44
        return $c->render(
44
        return $c->render(
Lines 51-58 sub list { Link Here
51
51
52
    return try {
52
    return try {
53
53
54
        my $holds_rs = $patron->holds;
54
        my $holds = $c->objects->search( $patron->holds );
55
        my $holds    = $c->objects->search( $holds_rs );
56
55
57
        return $c->render(
56
        return $c->render(
58
            status  => 200,
57
            status  => 200,
(-)a/Koha/REST/V1/Patrons/Password.pm (-4 / +4 lines)
Lines 44-51 sub set { Link Here
44
44
45
    my $c = shift->openapi->valid_input or return;
45
    my $c = shift->openapi->valid_input or return;
46
46
47
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
47
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
48
    my $body   = $c->validation->param('body');
48
    my $body   = $c->req->json;
49
49
50
    unless ($patron) {
50
    unless ($patron) {
51
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
51
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
Lines 87-94 sub set_public { Link Here
87
87
88
    my $c = shift->openapi->valid_input or return;
88
    my $c = shift->openapi->valid_input or return;
89
89
90
    my $body      = $c->validation->param('body');
90
    my $body      = $c->req->json;
91
    my $patron_id = $c->validation->param('patron_id');
91
    my $patron_id = $c->param('patron_id');
92
92
93
    my $user = $c->stash('koha.user');
93
    my $user = $c->stash('koha.user');
94
94
(-)a/Koha/REST/V1/Patrons/Password/Expiration.pm (-2 / +3 lines)
Lines 43-55 sub set { Link Here
43
43
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
46
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
47
    my $body   = $c->validation->param('body');
48
47
49
    unless ($patron) {
48
    unless ($patron) {
50
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
49
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
51
    }
50
    }
52
51
52
    my $body = $c->req->json;
53
53
    my $password_expiration_date   = $body->{expiration_date} // "";
54
    my $password_expiration_date   = $body->{expiration_date} // "";
54
55
55
    return try {
56
    return try {
(-)a/Koha/REST/V1/Quotes.pm (-9 / +10 lines)
Lines 35-42 sub list { Link Here
35
    my $c = shift->openapi->valid_input or return;
35
    my $c = shift->openapi->valid_input or return;
36
36
37
    return try {
37
    return try {
38
        my $quotes_set = Koha::Quotes->new;
38
        my $quotes = $c->objects->search( Koha::Quotes->new );
39
        my $quotes = $c->objects->search( $quotes_set );
40
        return $c->render( status => 200, openapi => $quotes );
39
        return $c->render( status => 200, openapi => $quotes );
41
    }
40
    }
42
    catch {
41
    catch {
Lines 53-62 sub get { Link Here
53
    my $c = shift->openapi->valid_input or return;
52
    my $c = shift->openapi->valid_input or return;
54
53
55
    return try {
54
    return try {
56
        my $quote = Koha::Quotes->find( $c->validation->param('quote_id') );
55
        my $quote = Koha::Quotes->find( $c->param('quote_id') );
57
        unless ($quote) {
56
        unless ($quote) {
58
            return $c->render( status  => 404,
57
            return $c->render(
59
                            openapi => { error => "quote not found" } );
58
                status  => 404,
59
                openapi => { error => "quote not found" }
60
            );
60
        }
61
        }
61
62
62
        return $c->render( status => 200, openapi => $quote->to_api );
63
        return $c->render( status => 200, openapi => $quote->to_api );
Lines 74-80 sub add { Link Here
74
    my $c = shift->openapi->valid_input or return;
75
    my $c = shift->openapi->valid_input or return;
75
76
76
    return try {
77
    return try {
77
        my $quote = Koha::Quote->new_from_api( $c->validation->param('body') );
78
        my $quote = Koha::Quote->new_from_api( $c->req->json );
78
        $quote->store;
79
        $quote->store;
79
        $c->res->headers->location( $c->req->url->to_string . '/' . $quote->id );
80
        $c->res->headers->location( $c->req->url->to_string . '/' . $quote->id );
80
        return $c->render(
81
        return $c->render(
Lines 94-100 sub add { Link Here
94
sub update {
95
sub update {
95
    my $c = shift->openapi->valid_input or return;
96
    my $c = shift->openapi->valid_input or return;
96
97
97
    my $quote = Koha::Quotes->find( $c->validation->param('quote_id') );
98
    my $quote = Koha::Quotes->find( $c->param('quote_id') );
98
99
99
    if ( not defined $quote ) {
100
    if ( not defined $quote ) {
100
        return $c->render( status  => 404,
101
        return $c->render( status  => 404,
Lines 102-108 sub update { Link Here
102
    }
103
    }
103
104
104
    return try {
105
    return try {
105
        $quote->set_from_api( $c->validation->param('body') );
106
        $quote->set_from_api( $c->req->json );
106
        $quote->store();
107
        $quote->store();
107
        return $c->render( status => 200, openapi => $quote->to_api );
108
        return $c->render( status => 200, openapi => $quote->to_api );
108
    }
109
    }
Lines 118-124 sub update { Link Here
118
sub delete {
119
sub delete {
119
    my $c = shift->openapi->valid_input or return;
120
    my $c = shift->openapi->valid_input or return;
120
121
121
    my $quote = Koha::Quotes->find( $c->validation->param('quote_id') );
122
    my $quote = Koha::Quotes->find( $c->param('quote_id') );
122
    if ( not defined $quote ) {
123
    if ( not defined $quote ) {
123
        return $c->render( status  => 404,
124
        return $c->render( status  => 404,
124
                           openapi => { error => "Object not found" } );
125
                           openapi => { error => "Object not found" } );
(-)a/Koha/REST/V1/ReturnClaims.pm (-7 / +7 lines)
Lines 40-46 Claim that a checked out item was returned. Link Here
40
40
41
sub claim_returned {
41
sub claim_returned {
42
    my $c    = shift->openapi->valid_input or return;
42
    my $c    = shift->openapi->valid_input or return;
43
    my $body = $c->validation->param('body');
43
    my $body = $c->req->json;
44
44
45
    return try {
45
    return try {
46
        my $itemnumber      = $body->{item_id};
46
        my $itemnumber      = $body->{item_id};
Lines 99-106 Update the notes of an existing claim Link Here
99
sub update_notes {
99
sub update_notes {
100
    my $c = shift->openapi->valid_input or return;
100
    my $c = shift->openapi->valid_input or return;
101
101
102
    my $claim_id = $c->validation->param('claim_id');
102
    my $claim_id = $c->param('claim_id');
103
    my $body     = $c->validation->param('body');
103
    my $body     = $c->req->json;
104
104
105
    my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
105
    my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
106
106
Lines 143-152 Marks a claim as resolved Link Here
143
=cut
143
=cut
144
144
145
sub resolve_claim {
145
sub resolve_claim {
146
    my $c     = shift->openapi->valid_input or return;
146
    my $c = shift->openapi->valid_input or return;
147
147
148
    my $claim_id = $c->validation->param('claim_id');
148
    my $claim_id = $c->param('claim_id');
149
    my $body     = $c->validation->param('body');
149
    my $body     = $c->req->json;
150
150
151
    my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
151
    my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
152
152
Lines 193-199 sub delete_claim { Link Here
193
193
194
    return try {
194
    return try {
195
195
196
        my $claim = Koha::Checkouts::ReturnClaims->find( $c->validation->param('claim_id') );
196
        my $claim = Koha::Checkouts::ReturnClaims->find( $c->param('claim_id') );
197
197
198
        return $c->render(
198
        return $c->render(
199
            status  => 404,
199
            status  => 404,
(-)a/Koha/REST/V1/SearchFilter.pm (-8 / +6 lines)
Lines 38-45 Controller function that handles listing Koha::SearchFilter objects Link Here
38
sub list {
38
sub list {
39
    my $c = shift->openapi->valid_input or return;
39
    my $c = shift->openapi->valid_input or return;
40
    return try {
40
    return try {
41
        my $filters_set = Koha::SearchFilters->search({});
41
        my $filters = $c->objects->search( Koha::SearchFilters->new );
42
        my $filters = $c->objects->search( $filters_set );
43
        return $c->render(
42
        return $c->render(
44
            status  => 200,
43
            status  => 200,
45
            openapi => $filters
44
            openapi => $filters
Lines 59-65 Controller function that handles retrieving a single Koha::AdvancedEditorMacro Link Here
59
58
60
sub get {
59
sub get {
61
    my $c = shift->openapi->valid_input or return;
60
    my $c = shift->openapi->valid_input or return;
62
    my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
61
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
63
    unless ($filter) {
62
    unless ($filter) {
64
        return $c->render( status  => 404,
63
        return $c->render( status  => 404,
65
                           openapi => { error => "Search filter not found" } );
64
                           openapi => { error => "Search filter not found" } );
Lines 78-84 sub add { Link Here
78
    my $c = shift->openapi->valid_input or return;
77
    my $c = shift->openapi->valid_input or return;
79
78
80
    return try {
79
    return try {
81
        my $filter = Koha::SearchFilter->new_from_api( $c->validation->param('body') );
80
        my $filter = Koha::SearchFilter->new_from_api( $c->req->json );
82
        $filter->store->discard_changes;
81
        $filter->store->discard_changes;
83
        $c->res->headers->location( $c->req->url->to_string . '/' . $filter->id );
82
        $c->res->headers->location( $c->req->url->to_string . '/' . $filter->id );
84
        return $c->render(
83
        return $c->render(
Lines 106-112 Controller function that handles updating a Koha::SearchFilter object Link Here
106
sub update {
105
sub update {
107
    my $c = shift->openapi->valid_input or return;
106
    my $c = shift->openapi->valid_input or return;
108
107
109
    my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
108
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
110
109
111
    if ( not defined $filter ) {
110
    if ( not defined $filter ) {
112
        return $c->render( status  => 404,
111
        return $c->render( status  => 404,
Lines 114-121 sub update { Link Here
114
    }
113
    }
115
114
116
    return try {
115
    return try {
117
        my $params = $c->req->json;
116
        $filter->set_from_api( $c->req->json );
118
        $filter->set_from_api( $params );
119
        $filter->store->discard_changes;
117
        $filter->store->discard_changes;
120
        return $c->render( status => 200, openapi => $filter->to_api );
118
        return $c->render( status => 200, openapi => $filter->to_api );
121
    }
119
    }
Lines 133-139 Controller function that handles deleting a Koha::SearchFilter object Link Here
133
sub delete {
131
sub delete {
134
    my $c = shift->openapi->valid_input or return;
132
    my $c = shift->openapi->valid_input or return;
135
133
136
    my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') );
134
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
137
    if ( not defined $filter ) {
135
    if ( not defined $filter ) {
138
        return $c->render( status  => 404,
136
        return $c->render( status  => 404,
139
                           openapi => { error => "Object not found" } );
137
                           openapi => { error => "Object not found" } );
(-)a/Koha/REST/V1/Stage.pm (-4 / +3 lines)
Lines 36-48 Move a stage up or down the stockrotation rota. Link Here
36
36
37
sub move {
37
sub move {
38
    my $c = shift->openapi->valid_input or return;
38
    my $c = shift->openapi->valid_input or return;
39
    my $input = $c->validation->output;
40
39
41
    my $rota  = Koha::StockRotationRotas->find( $input->{rota_id} );
40
    my $rota  = Koha::StockRotationRotas->find( $c->param('rota_id') );
42
    my $stage = Koha::StockRotationStages->find( $input->{stage_id} );
41
    my $stage = Koha::StockRotationStages->find( $c->param('stage_id') );
43
42
44
    if ( $stage && $rota ) {
43
    if ( $stage && $rota ) {
45
        my $result = $stage->move_to( $input->{position} );
44
        my $result = $stage->move_to( $c->req->json );
46
        return $c->render( openapi => {}, status => 200 ) if $result;
45
        return $c->render( openapi => {}, status => 200 ) if $result;
47
        return $c->render(
46
        return $c->render(
48
            openapi => { error => "Bad request - new position invalid" },
47
            openapi => { error => "Bad request - new position invalid" },
(-)a/Koha/REST/V1/Suggestions.pm (-8 / +5 lines)
Lines 63-70 sub get { Link Here
63
    my $c = shift->openapi->valid_input or return;
63
    my $c = shift->openapi->valid_input or return;
64
64
65
    return try {
65
    return try {
66
        my $suggestion_id = $c->validation->param('suggestion_id');
66
        my $suggestion = $c->objects->find( Koha::Suggestions->new, $c->param('suggestion_id') );
67
        my $suggestion = $c->objects->find( Koha::Suggestions->new, $suggestion_id );
68
67
69
        unless ($suggestion) {
68
        unless ($suggestion) {
70
            return $c->render(
69
            return $c->render(
Lines 92-98 Controller method that handles adding a new Koha::Suggestion object Link Here
92
sub add {
91
sub add {
93
    my $c = shift->openapi->valid_input or return;
92
    my $c = shift->openapi->valid_input or return;
94
93
95
    my $body = $c->validation->param('body');
94
    my $body = $c->req->json;
96
95
97
    # FIXME: This should be handled in Koha::Suggestion->store
96
    # FIXME: This should be handled in Koha::Suggestion->store
98
    $body->{'status'} = 'ASKED'
97
    $body->{'status'} = 'ASKED'
Lines 171-178 Controller method that handles modifying Koha::Suggestion object Link Here
171
sub update {
170
sub update {
172
    my $c = shift->openapi->valid_input or return;
171
    my $c = shift->openapi->valid_input or return;
173
172
174
    my $suggestion_id = $c->validation->param('suggestion_id');
173
    my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
175
    my $suggestion = Koha::Suggestions->find( $suggestion_id );
176
174
177
    return $c->render(
175
    return $c->render(
178
        status  => 404,
176
        status  => 404,
Lines 181-187 sub update { Link Here
181
179
182
    return try {
180
    return try {
183
181
184
        my $body = $c->validation->param('body');
182
        my $body = $c->req->json;
185
183
186
        $suggestion->set_from_api( $body )->store;
184
        $suggestion->set_from_api( $body )->store;
187
        $suggestion->discard_changes;
185
        $suggestion->discard_changes;
Lines 206-213 Controller method that handles removing a Koha::Suggestion object Link Here
206
sub delete {
204
sub delete {
207
    my $c = shift->openapi->valid_input or return;
205
    my $c = shift->openapi->valid_input or return;
208
206
209
    my $suggestion_id = $c->validation->param('suggestion_id');
207
    my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
210
    my $suggestion = Koha::Suggestions->find( $suggestion_id );
211
208
212
    return $c->render(
209
    return $c->render(
213
        status  => 404,
210
        status  => 404,
(-)a/Koha/REST/V1/Tickets.pm (-10 / +9 lines)
Lines 38-45 sub list { Link Here
38
    my $c = shift->openapi->valid_input or return;
38
    my $c = shift->openapi->valid_input or return;
39
39
40
    return try {
40
    return try {
41
        my $tickets_set = Koha::Tickets->new;
41
        my $tickets = $c->objects->search(Koha::Tickets->new);
42
        my $tickets     = $c->objects->search($tickets_set);
43
        return $c->render( status => 200, openapi => $tickets );
42
        return $c->render( status => 200, openapi => $tickets );
44
    }
43
    }
45
    catch {
44
    catch {
Lines 56-62 sub get { Link Here
56
    my $c = shift->openapi->valid_input or return;
55
    my $c = shift->openapi->valid_input or return;
57
56
58
    return try {
57
    return try {
59
        my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
58
        my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
60
        unless ($ticket) {
59
        unless ($ticket) {
61
            return $c->render(
60
            return $c->render(
62
                status  => 404,
61
                status  => 404,
Lines 80-86 sub add { Link Here
80
    my $patron = $c->stash('koha.user');
79
    my $patron = $c->stash('koha.user');
81
80
82
    return try {
81
    return try {
83
        my $body   = $c->validation->param('body');
82
        my $body = $c->req->json;
84
83
85
        # Set reporter from session
84
        # Set reporter from session
86
        $body->{reporter_id} = $patron->id;
85
        $body->{reporter_id} = $patron->id;
Lines 108-114 sub add { Link Here
108
sub update {
107
sub update {
109
    my $c = shift->openapi->valid_input or return;
108
    my $c = shift->openapi->valid_input or return;
110
109
111
    my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
110
    my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
112
111
113
    if ( not defined $ticket ) {
112
    if ( not defined $ticket ) {
114
        return $c->render(
113
        return $c->render(
Lines 118-124 sub update { Link Here
118
    }
117
    }
119
118
120
    return try {
119
    return try {
121
        $ticket->set_from_api( $c->validation->param('body') );
120
        $ticket->set_from_api( $c->req->json );
122
        $ticket->store();
121
        $ticket->store();
123
        return $c->render( status => 200, openapi => $ticket->to_api );
122
        return $c->render( status => 200, openapi => $ticket->to_api );
124
    }
123
    }
Lines 134-140 sub update { Link Here
134
sub delete {
133
sub delete {
135
    my $c = shift->openapi->valid_input or return;
134
    my $c = shift->openapi->valid_input or return;
136
135
137
    my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
136
    my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
138
    if ( not defined $ticket ) {
137
    if ( not defined $ticket ) {
139
        return $c->render(
138
        return $c->render(
140
            status  => 404,
139
            status  => 404,
Lines 162-168 sub list_updates { Link Here
162
    my $c = shift->openapi->valid_input or return;
161
    my $c = shift->openapi->valid_input or return;
163
162
164
    return try {
163
    return try {
165
        my $ticket = Koha::Tickets->find( $c->validation->param('ticket_id') );
164
        my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
166
        unless ($ticket) {
165
        unless ($ticket) {
167
            return $c->render(
166
            return $c->render(
168
                status  => 404,
167
                status  => 404,
Lines 187-194 sub add_update { Link Here
187
    my $c = shift->openapi->valid_input or return;
186
    my $c = shift->openapi->valid_input or return;
188
    my $patron = $c->stash('koha.user');
187
    my $patron = $c->stash('koha.user');
189
188
190
    my $ticket_id_param = $c->validation->param('ticket_id');
189
    my $ticket_id_param = $c->param('ticket_id');
191
    my $ticket_update   = $c->validation->param('body');
190
    my $ticket_update   = $c->req->json;
192
    $ticket_update->{ticket_id} //= $ticket_id_param;
191
    $ticket_update->{ticket_id} //= $ticket_id_param;
193
192
194
    if ( $ticket_update->{ticket_id} != $ticket_id_param ) {
193
    if ( $ticket_update->{ticket_id} != $ticket_id_param ) {
(-)a/Koha/REST/V1/TransferLimits.pm (-6 / +5 lines)
Lines 47-54 sub list { Link Here
47
    my $c = shift->openapi->valid_input or return;
47
    my $c = shift->openapi->valid_input or return;
48
48
49
    return try {
49
    return try {
50
        my $limits_set = Koha::Item::Transfer::Limits->new;
50
        my $limits = $c->objects->search( Koha::Item::Transfer::Limits->new );
51
        my $limits = $c->objects->search( $limits_set );
52
        return $c->render( status => 200, openapi => $limits );
51
        return $c->render( status => 200, openapi => $limits );
53
    }
52
    }
54
    catch {
53
    catch {
Lines 66-72 sub add { Link Here
66
    my $c = shift->openapi->valid_input or return;
65
    my $c = shift->openapi->valid_input or return;
67
66
68
    return try {
67
    return try {
69
        my $params = $c->validation->param( 'body' );
68
        my $params = $c->req->json;
70
        my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $params );
69
        my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $params );
71
70
72
        if ( Koha::Item::Transfer::Limits->search( $transfer_limit->attributes_from_api($params) )->count == 0 ) {
71
        if ( Koha::Item::Transfer::Limits->search( $transfer_limit->attributes_from_api($params) )->count == 0 ) {
Lines 102-108 sub delete { Link Here
102
101
103
    my $c = shift->openapi->valid_input or return;
102
    my $c = shift->openapi->valid_input or return;
104
103
105
    my $transfer_limit = Koha::Item::Transfer::Limits->find( $c->validation->param( 'limit_id' ) );
104
    my $transfer_limit = Koha::Item::Transfer::Limits->find( $c->param( 'limit_id' ) );
106
105
107
    if ( not defined $transfer_limit ) {
106
    if ( not defined $transfer_limit ) {
108
        return $c->render( status => 404, openapi => { error => "Transfer limit not found" } );
107
        return $c->render( status => 404, openapi => { error => "Transfer limit not found" } );
Lines 127-133 sub batch_add { Link Here
127
    my $c = shift->openapi->valid_input or return;
126
    my $c = shift->openapi->valid_input or return;
128
127
129
    return try {
128
    return try {
130
        my $params = $c->validation->param( 'body' );
129
        my $params = $c->req->json;
131
130
132
        my @libraries = Koha::Libraries->search->as_list;
131
        my @libraries = Koha::Libraries->search->as_list;
133
132
Lines 175-181 sub batch_delete { Link Here
175
    my $c = shift->openapi->valid_input or return;
174
    my $c = shift->openapi->valid_input or return;
176
175
177
    return try {
176
    return try {
178
        my $params = $c->validation->param( 'body' );
177
        my $params = $c->req->json;
179
        my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $params );
178
        my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $params );
180
        my $search_params = $transfer_limit->unblessed;
179
        my $search_params = $transfer_limit->unblessed;
181
180
(-)a/Koha/REST/V1/TwoFactorAuth.pm (-3 / +2 lines)
Lines 131-138 sub verification { Link Here
131
131
132
    return try {
132
    return try {
133
133
134
        my $pin_code = $c->validation->param('pin_code');
134
        my $pin_code = $c->param('pin_code');
135
        my $secret32 = $c->validation->param('secret32');
135
        my $secret32 = $c->param('secret32');
136
136
137
        my $auth     = Koha::Auth::TwoFactorAuth->new(
137
        my $auth     = Koha::Auth::TwoFactorAuth->new(
138
            { patron => $patron, secret32 => $secret32 } );
138
            { patron => $patron, secret32 => $secret32 } );
139
- 

Return to bug 33556