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

(-)a/Koha/REST/V1/Acquisitions/Orders.pm (-16 / +5 lines)
Lines 97-108 sub get { Link Here
97
97
98
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
98
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
99
99
100
    unless ($order) {
100
    return $c->render_resource_not_found("Order")
101
        return $c->render(
101
        unless $order;
102
            status  => 404,
103
            openapi => { error => "Order not found" }
104
        );
105
    }
106
102
107
    return try {
103
    return try {
108
        return $c->render(
104
        return $c->render(
Lines 160-171 sub update { Link Here
160
156
161
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
157
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
162
158
163
    unless ($order) {
159
    return $c->render_resource_not_found("Order")
164
        return $c->render(
160
        unless $order;
165
            status  => 404,
166
            openapi => { error => "Order not found" }
167
        );
168
    }
169
161
170
    return try {
162
    return try {
171
        $order->set_from_api( $c->req->json );
163
        $order->set_from_api( $c->req->json );
Lines 195-204 sub delete { Link Here
195
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
187
    my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
196
188
197
    unless ($order) {
189
    unless ($order) {
198
        return $c->render(
190
        return $c->render_resource_not_found("Order");
199
            status  => 404,
200
            openapi => { error => 'Order not found' }
201
        );
202
    } elsif ( ( $order->orderstatus && $order->orderstatus ne 'cancelled' ) || !$order->datecancellationprinted ) {
191
    } elsif ( ( $order->orderstatus && $order->orderstatus ne 'cancelled' ) || !$order->datecancellationprinted ) {
203
        # Koha may (historically) have inconsistent order data here (e.g. cancelled without date)
192
        # Koha may (historically) have inconsistent order data here (e.g. cancelled without date)
204
        return $c->render(
193
        return $c->render(
(-)a/Koha/REST/V1/Acquisitions/Vendor/Issues.pm (-6 / +2 lines)
Lines 48-59 sub list { Link Here
48
48
49
        my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
49
        my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
50
50
51
        unless ($vendor) {
51
        return $c->render_resource_not_found("Vendor")
52
            return $c->render(
52
            unless $vendor;
53
                status  => 404,
54
                openapi => { error => "Vendor not found." }
55
            );
56
        }
57
53
58
        my $issues_rs = $vendor->issues;
54
        my $issues_rs = $vendor->issues;
59
        my $issues    = $c->objects->search($issues_rs);
55
        my $issues    = $c->objects->search($issues_rs);
(-)a/Koha/REST/V1/Acquisitions/Vendors.pm (-23 / +11 lines)
Lines 63-74 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
    my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
65
    my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
66
    unless ($vendor) {
66
67
        return $c->render(
67
    return $c->render_resource_not_found("Vendor")
68
            status  => 404,
68
        unless $vendor;
69
            openapi => { error => "Vendor not found" }
70
        );
71
    }
72
69
73
    return try {
70
    return try {
74
        return $c->render(
71
        return $c->render(
Lines 114-138 Controller function that handles updating a Koha::Acquisition::Bookseller object Link Here
114
sub update {
111
sub update {
115
    my $c = shift->openapi->valid_input or return;
112
    my $c = shift->openapi->valid_input or return;
116
113
117
    my $vendor;
114
    my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
115
116
    return $c->render_resource_not_found("Vendor")
117
        unless $vendor;
118
118
119
    return try {
119
    return try {
120
        $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
121
        $vendor->set_from_api( $c->req->json );
120
        $vendor->set_from_api( $c->req->json );
122
        $vendor->store();
121
        $vendor->store();
122
123
        return $c->render(
123
        return $c->render(
124
            status  => 200,
124
            status  => 200,
125
            openapi => $c->objects->to_api($vendor),
125
            openapi => $c->objects->to_api($vendor),
126
        );
126
        );
127
    }
127
    } catch {
128
    catch {
129
        if ( not defined $vendor ) {
130
            return $c->render(
131
                status  => 404,
132
                openapi => { error => "Object not found" }
133
            );
134
        }
135
136
        $c->unhandled_exception($_);
128
        $c->unhandled_exception($_);
137
    };
129
    };
138
130
Lines 150-161 sub delete { Link Here
150
    return try {
142
    return try {
151
        my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
143
        my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
152
144
153
        unless ( $vendor ) {
145
        return $c->render_resource_not_found("Vendor")
154
            return $c->render(
146
            unless $vendor;
155
                status  => 404,
156
                openapi => { error => "Object not found" }
157
            );
158
        }
159
147
160
        $vendor->delete;
148
        $vendor->delete;
161
149
(-)a/Koha/REST/V1/AdvancedEditorMacro.pm (-26 / +19 lines)
Lines 67-78 sub get { Link Here
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( $c->param('advancededitormacro_id') );
69
    my $macro  = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
70
    unless ($macro) {
70
71
        return $c->render(
71
    return $c->render_resource_not_found("Macro")
72
            status  => 404,
72
        unless $macro;
73
            openapi => { error => "Macro not found" }
73
74
        );
75
    }
76
    if( $macro->shared ){
74
    if( $macro->shared ){
77
        return $c->render( status => 403, openapi => {
75
        return $c->render( status => 403, openapi => {
78
            error => "This macro is shared, you must access it via advanced_editor/macros/shared"
76
            error => "This macro is shared, you must access it via advanced_editor/macros/shared"
Lines 99-108 sub get_shared { Link Here
99
    my $macro = Koha::AdvancedEditorMacros->find({
97
    my $macro = Koha::AdvancedEditorMacros->find({
100
        id => $c->param('advancededitormacro_id'),
98
        id => $c->param('advancededitormacro_id'),
101
    });
99
    });
102
    unless ($macro) {
100
103
        return $c->render( status  => 404,
101
    return $c->render_resource_not_found("Macro")
104
                           openapi => { error => "Macro not found" } );
102
        unless $macro;
105
    }
103
106
    unless( $macro->shared ){
104
    unless( $macro->shared ){
107
        return $c->render( status => 403, openapi => {
105
        return $c->render( status => 403, openapi => {
108
            error => "This macro is not shared, you must access it via advanced_editor/macros"
106
            error => "This macro is not shared, you must access it via advanced_editor/macros"
Lines 181-190 sub update { Link Here
181
179
182
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
180
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
183
181
184
    if ( not defined $macro ) {
182
    return $c->render_resource_not_found("Macro")
185
        return $c->render( status  => 404,
183
        unless $macro;
186
                           openapi => { error => "Object not found" } );
184
187
    }
188
    my $patron = $c->stash('koha.user');
185
    my $patron = $c->stash('koha.user');
189
186
190
    my $body = $c->req->json;
187
    my $body = $c->req->json;
Lines 222-231 sub update_shared { Link Here
222
219
223
    my $body = $c->req->json;
220
    my $body = $c->req->json;
224
221
225
    if ( not defined $macro ) {
222
    return $c->render_resource_not_found("Macro")
226
        return $c->render( status  => 404,
223
        unless $macro;
227
                           openapi => { error => "Object not found" } );
228
    }
229
224
230
    unless( $macro->shared == 1 || defined $body->{shared} && $body->{shared} == 1 ){
225
    unless( $macro->shared == 1 || defined $body->{shared} && $body->{shared} == 1 ){
231
        return $c->render( status  => 403,
226
        return $c->render( status  => 403,
Lines 252-261 sub delete { Link Here
252
    my $c = shift->openapi->valid_input or return;
247
    my $c = shift->openapi->valid_input or return;
253
248
254
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
249
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
255
    if ( not defined $macro ) {
250
256
        return $c->render( status  => 404,
251
    return $c->render_resource_not_found("Macro")
257
                           openapi => { error => "Object not found" } );
252
        unless $macro;
258
    }
259
253
260
    my $patron = $c->stash('koha.user');
254
    my $patron = $c->stash('koha.user');
261
    if( $macro->shared == 1 ){
255
    if( $macro->shared == 1 ){
Lines 287-296 sub delete_shared { Link Here
287
    my $c = shift->openapi->valid_input or return;
281
    my $c = shift->openapi->valid_input or return;
288
282
289
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
283
    my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
290
    if ( not defined $macro ) {
284
291
        return $c->render( status  => 404,
285
    return $c->render_resource_not_found("Macro")
292
                           openapi => { error => "Object not found" } );
286
        unless $macro;
293
    }
294
287
295
    unless( $macro->shared == 1 ){
288
    unless( $macro->shared == 1 ){
296
        return $c->render( status  => 403,
289
        return $c->render( status  => 403,
(-)a/Koha/REST/V1/ArticleRequests.pm (-18 / +6 lines)
Lines 44-55 sub cancel { Link Here
44
44
45
    my $article_request = Koha::ArticleRequests->find( $c->param('article_request_id') );
45
    my $article_request = Koha::ArticleRequests->find( $c->param('article_request_id') );
46
46
47
    unless ( $article_request ) {
47
    return $c->render_resource_not_found("Article request")
48
        return $c->render(
48
        unless $article_request;
49
            status  => 404,
50
            openapi => { error => "Article request not found" }
51
        );
52
    }
53
49
54
    my $reason = $c->param('cancellation_reason');
50
    my $reason = $c->param('cancellation_reason');
55
    my $notes  = $c->param('notes');
51
    my $notes  = $c->param('notes');
Lines 82-104 sub patron_cancel { Link Here
82
78
83
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
79
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
84
80
85
    unless ( $patron ) {
81
    return $c->render_resource_not_found("Patron")
86
        return $c->render(
82
        unless $patron;
87
            status  => 404,
88
            openapi => { error => "Patron not found" }
89
        );
90
    }
91
83
92
    # patron_id has been validated by the allow-owner check, so the following call to related
84
    # 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
85
    # article requests covers the case of article requests not belonging to the patron
94
    my $article_request = $patron->article_requests->find( $c->param('article_request_id') );
86
    my $article_request = $patron->article_requests->find( $c->param('article_request_id') );
95
87
96
    unless ( $article_request ) {
88
    return $c->render_resource_not_found("Article request")
97
        return $c->render(
89
        unless $article_request;
98
            status  => 404,
99
            openapi => { error => "Article request not found" }
100
        );
101
    }
102
90
103
    my $reason = $c->param('cancellation_reason');
91
    my $reason = $c->param('cancellation_reason');
104
    my $notes  = $c->param('notes');
92
    my $notes  = $c->param('notes');
(-)a/Koha/REST/V1/Auth/Identity/Provider/Domains.pm (-45 / +10 lines)
Lines 46-60 sub list { Link Here
46
    return try {
46
    return try {
47
        my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
47
        my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
48
48
49
        unless ($provider) {
49
        return $c->render_resource_not_found("Identity provider")
50
            return $c->render(
50
            unless $provider;
51
                status  => 404,
52
                openapi => {
53
                    error      => 'Object not found',
54
                    error_code => 'not_found',
55
                }
56
            );
57
        }
58
51
59
        my $domains_rs = $provider->domains;
52
        my $domains_rs = $provider->domains;
60
        return $c->render(
53
        return $c->render(
Lines 79-107 sub get { Link Here
79
72
80
        my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
73
        my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
81
74
82
        unless ($provider) {
75
        return $c->render_resource_not_found("Identity provider")
83
            return $c->render(
76
            unless $provider;
84
                status  => 404,
85
                openapi => {
86
                    error      => 'Object not found',
87
                    error_code => 'not_found',
88
                }
89
            );
90
        }
91
77
92
        my $domains_rs = $provider->domains;
78
        my $domains_rs = $provider->domains;
93
79
94
        my $domain = $c->objects->find( $domains_rs, $c->param('identity_provider_domain_id') );
80
        my $domain = $c->objects->find( $domains_rs, $c->param('identity_provider_domain_id') );
95
81
96
        unless ($domain) {
82
        return $c->render_resource_not_found("Identity provider domain")
97
            return $c->render(
83
            unless $domain;
98
                status  => 404,
99
                openapi => {
100
                    error      => 'Object not found',
101
                    error_code => 'not_found',
102
                }
103
            );
104
        }
105
84
106
        return $c->render( status => 200, openapi => $domain );
85
        return $c->render( status => 200, openapi => $domain );
107
    } catch {
86
    } catch {
Lines 164-178 sub update { Link Here
164
        }
143
        }
165
    );
144
    );
166
145
167
    unless ($domain) {
146
    return $c->render_resource_not_found("Identity provider domain")
168
        return $c->render(
147
        unless $domain;
169
            status  => 404,
170
            openapi => {
171
                error      => 'Object not found',
172
                error_code => 'not_found',
173
            }
174
        );
175
    }
176
148
177
    return try {
149
    return try {
178
150
Lines 209-223 sub delete { Link Here
209
        }
181
        }
210
    );
182
    );
211
183
212
    unless ($domain) {
184
    return $c->render_resource_not_found("Identity provider domain")
213
        return $c->render(
185
        unless $domain;
214
            status  => 404,
215
            openapi => {
216
                error      => 'Object not found',
217
                error_code => 'not_found',
218
            }
219
        );
220
    }
221
186
222
    return try {
187
    return try {
223
        $domain->delete;
188
        $domain->delete;
(-)a/Koha/REST/V1/Auth/Identity/Providers.pm (-27 / +7 lines)
Lines 68-82 sub get { Link Here
68
68
69
        my $provider = $c->objects->find( Koha::Auth::Identity::Providers->new, $c->param('identity_provider_id') );
69
        my $provider = $c->objects->find( Koha::Auth::Identity::Providers->new, $c->param('identity_provider_id') );
70
70
71
        unless ( $provider ) {
71
        return $c->render_resource_not_found("Identity provider")
72
            return $c->render(
72
            unless $provider;
73
                status  => 404,
74
                openapi => {
75
                    error      => 'Object not found',
76
                    error_code => 'not_found',
77
                }
78
            );
79
        }
80
73
81
        return $c->render( status => 200, openapi => $provider );
74
        return $c->render( status => 200, openapi => $provider );
82
    }
75
    }
Lines 148-162 sub update { Link Here
148
141
149
    my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
142
    my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
150
143
151
    unless ( $provider ) {
144
    return $c->render_resource_not_found("Identity provider")
152
        return $c->render(
145
        unless $provider;
153
            status  => 404,
154
            openapi => {
155
                error      => 'Object not found',
156
                error_code => 'not_found',
157
            }
158
        );
159
    }
160
146
161
    return try {
147
    return try {
162
148
Lines 210-224 sub delete { Link Here
210
    my $c = shift->openapi->valid_input or return;
196
    my $c = shift->openapi->valid_input or return;
211
197
212
    my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
198
    my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
213
    unless ( $provider ) {
199
214
        return $c->render(
200
    return $c->render_resource_not_found("Identity provider")
215
            status  => 404,
201
        unless $provider;
216
            openapi => {
217
                error      => 'Object not found',
218
                error_code => 'not_found',
219
            }
220
        );
221
    }
222
202
223
    return try {
203
    return try {
224
        $provider->delete;
204
        $provider->delete;
(-)a/Koha/REST/V1/AuthorisedValues.pm (-6 / +2 lines)
Lines 38-49 sub list_av_from_category { Link Here
38
38
39
    my $category = Koha::AuthorisedValueCategories->find($c->param('authorised_value_category_name'));
39
    my $category = Koha::AuthorisedValueCategories->find($c->param('authorised_value_category_name'));
40
40
41
    unless ($category) {
41
    return $c->render_resource_not_found("Category")
42
        return $c->render(
42
        unless $category;
43
            status  => 404,
44
            openapi => { error => "Category not found" }
45
        );
46
    }
47
43
48
    return try {
44
    return try {
49
        my $av_set = $category->authorised_values->search_with_library_limits;
45
        my $av_set = $category->authorised_values->search_with_library_limits;
(-)a/Koha/REST/V1/Authorities.pm (-20 / +7 lines)
Lines 41-54 sub get { Link Here
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->param('authority_id') } );
43
    my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
44
    unless ( $authority ) {
44
45
        return $c->render(
45
    return $c->render_resource_not_found("Authority record")
46
            status  => 404,
46
        unless $authority;
47
            openapi => {
48
                error => "Object not found."
49
            }
50
        );
51
    }
52
47
53
    return try {
48
    return try {
54
49
Lines 111-122 sub delete { Link Here
111
106
112
    my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
107
    my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
113
108
114
    if ( not defined $authority ) {
109
    return $c->render_resource_not_found("Authority record")
115
        return $c->render(
110
        unless $authority;
116
            status  => 404,
117
            openapi => { error => "Object not found" }
118
        );
119
    }
120
111
121
    return try {
112
    return try {
122
        DelAuthority( { authid => $authority->authid } );
113
        DelAuthority( { authid => $authority->authid } );
Lines 206-217 sub update { Link Here
206
    my $authid = $c->param('authority_id');
197
    my $authid = $c->param('authority_id');
207
    my $authority = Koha::Authorities->find( { authid => $authid } );
198
    my $authority = Koha::Authorities->find( { authid => $authid } );
208
199
209
    if ( not defined $authority ) {
200
    return $c->render_resource_not_found("Authority record")
210
        return $c->render(
201
        unless $authority;
211
            status  => 404,
212
            openapi => { error => "Object not found" }
213
        );
214
    }
215
202
216
    try {
203
    try {
217
        my $headers = $c->req->headers;
204
        my $headers = $c->req->headers;
(-)a/Koha/REST/V1/BackgroundJobs.pm (-4 / +2 lines)
Lines 75-84 sub get { Link Here
75
75
76
        my $job = Koha::BackgroundJobs->find($job_id);
76
        my $job = Koha::BackgroundJobs->find($job_id);
77
77
78
        return $c->render(
78
        return $c->render_resource_not_found("Job")
79
            status  => 404,
79
            unless $job;
80
            openapi => { error => "Object not found" }
81
        ) unless $job;
82
80
83
        return $c->render(
81
        return $c->render(
84
            status  => 403,
82
            status  => 403,
(-)a/Koha/REST/V1/Biblios.pm (-94 / +29 lines)
Lines 56-69 sub get { Link Here
56
56
57
    my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
57
    my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
58
58
59
    unless ( $biblio ) {
59
    return $c->render_resource_not_found("Bibliographic record")
60
        return $c->render(
60
        unless $biblio;
61
            status  => 404,
62
            openapi => {
63
                error => "Object not found."
64
            }
65
        );
66
    }
67
61
68
    return try {
62
    return try {
69
63
Lines 128-139 sub delete { Link Here
128
122
129
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
123
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
130
124
131
    if ( not defined $biblio ) {
125
    return $c->render_resource_not_found("Bibliographic record")
132
        return $c->render(
126
        unless $biblio;
133
            status  => 404,
134
            openapi => { error => "Object not found" }
135
        );
136
    }
137
127
138
    return try {
128
    return try {
139
        my $error = DelBiblio( $biblio->id );
129
        my $error = DelBiblio( $biblio->id );
Lines 166-179 sub get_public { Link Here
166
        { biblionumber => $c->param('biblio_id') },
156
        { biblionumber => $c->param('biblio_id') },
167
        { prefetch     => ['metadata'] } );
157
        { prefetch     => ['metadata'] } );
168
158
169
    unless ($biblio) {
159
    return $c->render_resource_not_found("Bibliographic record")
170
        return $c->render(
160
        unless $biblio;
171
            status  => 404,
172
            openapi => {
173
                error => "Object not found."
174
            }
175
        );
176
    }
177
161
178
    return try {
162
    return try {
179
163
Lines 187-200 sub get_public { Link Here
187
        # unless there's a logged in user, and there's an exception for it's
171
        # unless there's a logged in user, and there's an exception for it's
188
        # category
172
        # category
189
        unless ( $patron and $patron->category->override_hidden_items ) {
173
        unless ( $patron and $patron->category->override_hidden_items ) {
190
            if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) )
174
            if ( $biblio->hidden_in_opac( { rules => $opachiddenitems_rules } ) ) {
191
            {
175
                return $c->render_resource_not_found("Bibliographic record");
192
                return $c->render(
193
                    status  => 404,
194
                    openapi => {
195
                        error => "Object not found."
196
                    }
197
                );
198
            }
176
            }
199
        }
177
        }
200
178
Lines 259-270 sub get_bookings { Link Here
259
237
260
    my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['bookings'] } );
238
    my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['bookings'] } );
261
239
262
    unless ($biblio) {
240
    return $c->render_resource_not_found("Bibliographic record")
263
        return $c->render(
241
        unless $biblio;
264
            status  => 404,
265
            openapi => { error => "Object not found." }
266
        );
267
    }
268
242
269
    return try {
243
    return try {
270
244
Lines 291-302 sub get_items { Link Here
291
    my $biblio        = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } );
265
    my $biblio        = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } );
292
    my $bookable_only = $c->param('bookable');
266
    my $bookable_only = $c->param('bookable');
293
267
294
    unless ($biblio) {
268
    return $c->render_resource_not_found("Bibliographic record")
295
        return $c->render(
269
        unless $biblio;
296
            status  => 404,
297
            openapi => { error => "Object not found." }
298
        );
299
    }
300
270
301
    return try {
271
    return try {
302
272
Lines 330-341 sub add_item { Link Here
330
        my $biblio_id = $c->param('biblio_id');
300
        my $biblio_id = $c->param('biblio_id');
331
        my $biblio    = Koha::Biblios->find( $biblio_id );
301
        my $biblio    = Koha::Biblios->find( $biblio_id );
332
302
333
        unless ($biblio) {
303
        return $c->render_resource_not_found("Bibliographic record")
334
            return $c->render(
304
            unless $biblio;
335
                status  => 404,
336
                openapi => { error => "Biblio not found" }
337
            );
338
        }
339
305
340
        my $body = $c->req->json;
306
        my $body = $c->req->json;
341
307
Lines 443-463 sub update_item { Link Here
443
        my $biblio_id = $c->param('biblio_id');
409
        my $biblio_id = $c->param('biblio_id');
444
        my $item_id   = $c->param('item_id');
410
        my $item_id   = $c->param('item_id');
445
        my $biblio    = Koha::Biblios->find( { biblionumber => $biblio_id } );
411
        my $biblio    = Koha::Biblios->find( { biblionumber => $biblio_id } );
446
        unless ($biblio) {
412
447
            return $c->render(
413
        return $c->render_resource_not_found("Bibliographic record")
448
                status  => 404,
414
            unless $biblio;
449
                openapi => { error => "Biblio not found" }
450
            );
451
        }
452
415
453
        my $item = $biblio->items->find({ itemnumber => $item_id });
416
        my $item = $biblio->items->find({ itemnumber => $item_id });
454
417
455
        unless ($item) {
418
        return $c->render_resource_not_found("Item")
456
            return $c->render(
419
            unless $item;
457
                status  => 404,
458
                openapi => { error => "Item not found" }
459
            );
460
        }
461
420
462
        my $body = $c->req->json;
421
        my $body = $c->req->json;
463
422
Lines 501-512 sub get_checkouts { Link Here
501
    try {
460
    try {
502
        my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
461
        my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
503
462
504
        unless ($biblio) {
463
        return $c->render_resource_not_found("Bibliographic record")
505
            return $c->render(
464
            unless $biblio;
506
                status  => 404,
507
                openapi => { error => 'Object not found' }
508
            );
509
        }
510
465
511
        my $checkouts =
466
        my $checkouts =
512
          ($checked_in)
467
          ($checked_in)
Lines 535-546 sub pickup_locations { Link Here
535
490
536
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
491
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
537
492
538
    unless ($biblio) {
493
    return $c->render_resource_not_found("Bibliographic record")
539
        return $c->render(
494
        unless $biblio;
540
            status  => 404,
541
            openapi => { error => "Biblio not found" }
542
        );
543
    }
544
495
545
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
496
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
546
    $c->req->params->remove('patron_id');
497
    $c->req->params->remove('patron_id');
Lines 604-617 sub get_items_public { Link Here
604
        { prefetch => ['items'] }
555
        { prefetch => ['items'] }
605
    );
556
    );
606
557
607
    unless ( $biblio ) {
558
    return $c->render_resource_not_found("Bibliographic record")
608
        return $c->render(
559
        unless $biblio;
609
            status  => 404,
610
            openapi => {
611
                error => "Object not found."
612
            }
613
        );
614
    }
615
560
616
    return try {
561
    return try {
617
562
Lines 641-654 sub set_rating { Link Here
641
586
642
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
587
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
643
588
644
    unless ($biblio) {
589
    $c->render_resource_not_found("Bibliographic record")
645
        return $c->render(
590
        unless $biblio;
646
            status  => 404,
647
            openapi => {
648
                error => "Object not found."
649
            }
650
        );
651
    }
652
591
653
    my $patron = $c->stash('koha.user');
592
    my $patron = $c->stash('koha.user');
654
    unless ($patron) {
593
    unless ($patron) {
Lines 775-786 sub update { Link Here
775
714
776
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
715
    my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
777
716
778
    if ( ! defined $biblio ) {
717
    $c->render_resource_not_found("Bibliographic record")
779
        return $c->render(
718
        unless $biblio;
780
            status  => 404,
781
            openapi => { error => "Object not found" }
782
        );
783
    }
784
719
785
    try {
720
    try {
786
        my $headers = $c->req->headers;
721
        my $headers = $c->req->headers;
(-)a/Koha/REST/V1/Biblios/ItemGroups.pm (-6 / +2 lines)
Lines 206-217 sub delete { Link Here
206
        }
206
        }
207
    );
207
    );
208
208
209
    if ( not defined $item_group ) {
209
    return $c->render_resource_not_found("Item group")
210
        return $c->render(
210
        unless $item_group;
211
            status  => 404,
212
            openapi => { error => "Item group not found" }
213
        );
214
    }
215
211
216
    return try {
212
    return try {
217
        $item_group->delete;
213
        $item_group->delete;
(-)a/Koha/REST/V1/Biblios/ItemGroups/Items.pm (-8 / +2 lines)
Lines 45-58 sub add { Link Here
45
45
46
        my $item_group = Koha::Biblio::ItemGroups->find( $c->param('item_group_id') );
46
        my $item_group = Koha::Biblio::ItemGroups->find( $c->param('item_group_id') );
47
47
48
        unless ( $item_group ) {
48
        return $c->render_resource_not_found("Item group")
49
            return $c->render(
49
            unless $item_group;
50
                status  => 404,
51
                openapi => {
52
                    error => 'Item group not found'
53
                }
54
            );
55
        }
56
50
57
        unless ( $item_group->biblio_id eq $c->param('biblio_id') ) {
51
        unless ( $item_group->biblio_id eq $c->param('biblio_id') ) {
58
            return $c->render(
52
            return $c->render(
(-)a/Koha/REST/V1/Bookings.pm (-18 / +7 lines)
Lines 55-66 sub get { Link Here
55
55
56
    return try {
56
    return try {
57
        my $booking = $c->objects->find( Koha::Bookings->new, $c->param('booking_id') );
57
        my $booking = $c->objects->find( Koha::Bookings->new, $c->param('booking_id') );
58
        unless ($booking) {
58
59
            return $c->render(
59
        return $c->render_resource_not_found("Booking")
60
                status  => 404,
60
            unless $booking;
61
                openapi => { error => "Booking not found" }
62
            );
63
        }
64
61
65
        return $c->render( status => 200, openapi => $booking );
62
        return $c->render( status => 200, openapi => $booking );
66
    } catch {
63
    } catch {
Lines 115-126 sub update { Link Here
115
112
116
    my $booking = $c->objects->find_rs( Koha::Bookings->new, $c->param('booking_id') );
113
    my $booking = $c->objects->find_rs( Koha::Bookings->new, $c->param('booking_id') );
117
114
118
    if ( not defined $booking ) {
115
    return $c->render_resource_not_found("Booking")
119
        return $c->render(
116
        unless $booking;
120
            status  => 404,
121
            openapi => { error => "Object not found" }
122
        );
123
    }
124
117
125
    return try {
118
    return try {
126
        $booking->set_from_api( $c->req->json );
119
        $booking->set_from_api( $c->req->json );
Lines 142-153 sub delete { Link Here
142
135
143
    my $booking = Koha::Bookings->find( $c->param('booking_id') );
136
    my $booking = Koha::Bookings->find( $c->param('booking_id') );
144
137
145
    unless ( $booking ) {
138
    return $c->render_resource_not_found("Booking")
146
        return $c->render(
139
        unless $booking;
147
            status  => 404,
148
            openapi => { error => "Object not found" }
149
        );
150
    }
151
140
152
    return try {
141
    return try {
153
        $booking->delete;
142
        $booking->delete;
(-)a/Koha/REST/V1/CashRegisters/Cashups.pm (-6 / +3 lines)
Lines 71-82 sub get { Link Here
71
71
72
    return try {
72
    return try {
73
        my $cashup = Koha::Cash::Register::Cashups->find( $c->param('cashup_id') );
73
        my $cashup = Koha::Cash::Register::Cashups->find( $c->param('cashup_id') );
74
        unless ($cashup) {
74
75
            return $c->render(
75
        return $c->render_resource_not_found("Cashup")
76
                status  => 404,
76
            unless $cashup;
77
                openapi => { error => "Cashup not found" }
78
            );
79
        }
80
77
81
        return $c->render(
78
        return $c->render(
82
            status  => 200,
79
            status  => 200,
(-)a/Koha/REST/V1/Checkouts.pm (-29 / +15 lines)
Lines 79-94 sub get { Link Here
79
    my $c = shift->openapi->valid_input or return;
79
    my $c = shift->openapi->valid_input or return;
80
80
81
    my $checkout_id = $c->param('checkout_id');
81
    my $checkout_id = $c->param('checkout_id');
82
    my $checkout = Koha::Checkouts->find( $checkout_id );
83
    $checkout = Koha::Old::Checkouts->find( $checkout_id )
84
        unless ($checkout);
85
82
86
    unless ($checkout) {
83
    my $checkout = Koha::Checkouts->find($checkout_id);
87
        return $c->render(
84
    $checkout = Koha::Old::Checkouts->find($checkout_id)
88
            status => 404,
85
        unless $checkout;
89
            openapi => { error => "Checkout doesn't exist" }
86
90
        );
87
    return $c->render_resource_not_found("Checkout")
91
    }
88
        unless $checkout;
92
89
93
    return try {
90
    return try {
94
        return $c->render(
91
        return $c->render(
Lines 295-310 sub get_renewals { Link Here
295
292
296
    try {
293
    try {
297
        my $checkout_id = $c->param('checkout_id');
294
        my $checkout_id = $c->param('checkout_id');
298
        my $checkout    = Koha::Checkouts->find($checkout_id);
295
296
        my $checkout = Koha::Checkouts->find($checkout_id);
299
        $checkout = Koha::Old::Checkouts->find($checkout_id)
297
        $checkout = Koha::Old::Checkouts->find($checkout_id)
300
          unless ($checkout);
298
            unless $checkout;
301
299
302
        unless ($checkout) {
300
        return $c->render_resource_not_found("Checkout")
303
            return $c->render(
301
            unless $checkout;
304
                status  => 404,
305
                openapi => { error => "Checkout doesn't exist" }
306
            );
307
        }
308
302
309
        my $renewals_rs = $checkout->renewals;
303
        my $renewals_rs = $checkout->renewals;
310
        my $renewals = $c->objects->search( $renewals_rs );
304
        my $renewals = $c->objects->search( $renewals_rs );
Lines 333-344 sub renew { Link Here
333
    my $seen = $c->param('seen') || 1;
327
    my $seen = $c->param('seen') || 1;
334
    my $checkout = Koha::Checkouts->find( $checkout_id );
328
    my $checkout = Koha::Checkouts->find( $checkout_id );
335
329
336
    unless ($checkout) {
330
    return $c->render_resource_not_found("Checkout")
337
        return $c->render(
331
        unless $checkout;
338
            status => 404,
339
            openapi => { error => "Checkout doesn't exist" }
340
        );
341
    }
342
332
343
    return try {
333
    return try {
344
        my ($can_renew, $error) = CanBookBeRenewed($checkout->patron, $checkout);
334
        my ($can_renew, $error) = CanBookBeRenewed($checkout->patron, $checkout);
Lines 383-394 sub allows_renewal { Link Here
383
    my $checkout_id = $c->param('checkout_id');
373
    my $checkout_id = $c->param('checkout_id');
384
    my $checkout = Koha::Checkouts->find( $checkout_id );
374
    my $checkout = Koha::Checkouts->find( $checkout_id );
385
375
386
    unless ($checkout) {
376
    return $c->render_resource_not_found("Checkout")
387
        return $c->render(
377
        unless $checkout;
388
            status => 404,
389
            openapi => { error => "Checkout doesn't exist" }
390
        );
391
    }
392
378
393
    return try {
379
    return try {
394
        my ($can_renew, $error) = CanBookBeRenewed($checkout->patron, $checkout);
380
        my ($can_renew, $error) = CanBookBeRenewed($checkout->patron, $checkout);
(-)a/Koha/REST/V1/Cities.pm (-15 / +9 lines)
Lines 53-68 sub get { Link Here
53
53
54
    return try {
54
    return try {
55
        my $city = Koha::Cities->find( $c->param('city_id') );
55
        my $city = Koha::Cities->find( $c->param('city_id') );
56
        unless ($city) {
56
        return $c->render_resource_not_found("City")
57
            return $c->render( status  => 404,
57
            unless $city;
58
                            openapi => { error => "City not found" } );
59
        }
60
58
61
        return $c->render( status => 200, openapi => $c->objects->to_api($city), );
59
        return $c->render( status => 200, openapi => $c->objects->to_api($city), );
62
    }
60
    } catch {
63
    catch {
64
        $c->unhandled_exception($_);
61
        $c->unhandled_exception($_);
65
    }
62
    };
66
}
63
}
67
64
68
=head3 add
65
=head3 add
Lines 95-104 sub update { Link Here
95
92
96
    my $city = Koha::Cities->find( $c->param('city_id') );
93
    my $city = Koha::Cities->find( $c->param('city_id') );
97
94
98
    if ( not defined $city ) {
95
    return $c->render_resource_not_found("City")
99
        return $c->render( status  => 404,
96
        unless $city;
100
                           openapi => { error => "Object not found" } );
101
    }
102
97
103
    return try {
98
    return try {
104
        $city->set_from_api( $c->req->json );
99
        $city->set_from_api( $c->req->json );
Lines 118-127 sub delete { Link Here
118
    my $c = shift->openapi->valid_input or return;
113
    my $c = shift->openapi->valid_input or return;
119
114
120
    my $city = Koha::Cities->find( $c->param('city_id') );
115
    my $city = Koha::Cities->find( $c->param('city_id') );
121
    if ( not defined $city ) {
116
122
        return $c->render( status  => 404,
117
    return $c->render_resource_not_found("City")
123
                           openapi => { error => "Object not found" } );
118
        unless $city;
124
    }
125
119
126
    return try {
120
    return try {
127
        $city->delete;
121
        $city->delete;
(-)a/Koha/REST/V1/Clubs/Holds.pm (-10 / +3 lines)
Lines 76-85 sub add { Link Here
76
            my $item = Koha::Items->find($item_id);
76
            my $item = Koha::Items->find($item_id);
77
77
78
            unless ($item) {
78
            unless ($item) {
79
                return $c->render(
79
                return $c->render_resource_not_found("Item");
80
                    status  => 404,
81
                    openapi => { error => "Item not found" }
82
                );
83
            }
80
            }
84
            else {
81
            else {
85
                $biblio = $item->biblio;
82
                $biblio = $item->biblio;
Lines 95-106 sub add { Link Here
95
            );
92
            );
96
        }
93
        }
97
94
98
        unless ($biblio) {
95
        return $c->render_resource_not_found("Bibliographic record")
99
            return $c->render(
96
            unless $biblio;
100
                status  => 404,
101
                openapi => { error => "Biblio not found" }
102
            );
103
        }
104
97
105
        my $club_hold = Koha::Club::Hold::add(
98
        my $club_hold = Koha::Club::Hold::add(
106
            {
99
            {
(-)a/Koha/REST/V1/Config/SMTP/Servers.pm (-20 / +6 lines)
Lines 61-74 sub get { Link Here
61
    return try {
61
    return try {
62
        my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
62
        my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
63
63
64
        unless ($smtp_server) {
64
        return $c->render_resource_not_found("SMTP server")
65
            return $c->render(
65
            unless $smtp_server;
66
                status  => 404,
67
                openapi => {
68
                    error => "SMTP server not found"
69
                }
70
            );
71
        }
72
66
73
        return $c->render(
67
        return $c->render(
74
            status  => 200,
68
            status  => 200,
Lines 127-140 sub update { Link Here
127
121
128
    my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
122
    my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
129
123
130
    if ( not defined $smtp_server ) {
124
    return $c->render_resource_not_found("SMTP server")
131
        return $c->render(
125
        unless $smtp_server;
132
            status  => 404,
133
            openapi => {
134
                error => "Object not found"
135
            }
136
        );
137
    }
138
126
139
    return try {
127
    return try {
140
        $smtp_server->set_from_api( $c->req->json );
128
        $smtp_server->set_from_api( $c->req->json );
Lines 171-180 sub delete { Link Here
171
159
172
    my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
160
    my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
173
161
174
    if ( not defined $smtp_server ) {
162
    return $c->render_resource_not_found("SMTP server")
175
        return $c->render( status  => 404,
163
        unless $smtp_server;
176
                           openapi => { error => "Object not found" } );
177
    }
178
164
179
    return try {
165
    return try {
180
        $smtp_server->delete;
166
        $smtp_server->delete;
(-)a/Koha/REST/V1/ERM/Agreements.pm (-18 / +7 lines)
Lines 64-75 sub get { Link Here
64
    return try {
64
    return try {
65
        my $agreement = $c->objects->find( Koha::ERM::Agreements->search, $c->param('agreement_id') );
65
        my $agreement = $c->objects->find( Koha::ERM::Agreements->search, $c->param('agreement_id') );
66
66
67
        unless ($agreement) {
67
        return $c->render_resource_not_found("Agreement")
68
            return $c->render(
68
            unless $agreement;
69
                status  => 404,
70
                openapi => { error => "Agreement not found" }
71
            );
72
        }
73
69
74
        return $c->render(
70
        return $c->render(
75
            status  => 200,
71
            status  => 200,
Lines 171-182 sub update { Link Here
171
167
172
    my $agreement = Koha::ERM::Agreements->find( $c->param('agreement_id') );
168
    my $agreement = Koha::ERM::Agreements->find( $c->param('agreement_id') );
173
169
174
    unless ($agreement) {
170
    return $c->render_resource_not_found("Agreement")
175
        return $c->render(
171
        unless $agreement;
176
            status  => 404,
177
            openapi => { error => "Agreement not found" }
178
        );
179
    }
180
172
181
    return try {
173
    return try {
182
        Koha::Database->new->schema->txn_do(
174
        Koha::Database->new->schema->txn_do(
Lines 249-260 sub delete { Link Here
249
    my $c = shift->openapi->valid_input or return;
241
    my $c = shift->openapi->valid_input or return;
250
242
251
    my $agreement = Koha::ERM::Agreements->find( $c->param('agreement_id') );
243
    my $agreement = Koha::ERM::Agreements->find( $c->param('agreement_id') );
252
    unless ($agreement) {
244
253
        return $c->render(
245
    return $c->render_resource_not_found("Agreement")
254
            status  => 404,
246
        unless $agreement;
255
            openapi => { error => "Agreement not found" }
256
        );
257
    }
258
247
259
    return try {
248
    return try {
260
        $agreement->delete;
249
        $agreement->delete;
(-)a/Koha/REST/V1/ERM/Documents.pm (-6 / +2 lines)
Lines 42-53 sub get { Link Here
42
        # Do not use $c->objects->find here, we need the file_content
42
        # Do not use $c->objects->find here, we need the file_content
43
        my $document = Koha::ERM::Documents->find( $c->param('document_id') );
43
        my $document = Koha::ERM::Documents->find( $c->param('document_id') );
44
44
45
        if ( !$document ) {
45
        return $c->render_resource_not_found("Document")
46
            return $c->render(
46
            unless $document;
47
                status  => 404,
48
                openapi => { error => "Document not found" }
49
            );
50
        }
51
47
52
        $c->render_file('data' => $document->file_content, 'filename' => $document->file_name);
48
        $c->render_file('data' => $document->file_content, 'filename' => $document->file_name);
53
    }
49
    }
(-)a/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm (-18 / +7 lines)
Lines 59-70 sub get { Link Here
59
            $package_id
59
            $package_id
60
        );
60
        );
61
61
62
        unless ($package) {
62
        return $c->render_resource_not_found("Package")
63
            return $c->render(
63
            unless $package;
64
                status  => 404,
65
                openapi => { error => "Package not found" }
66
            );
67
        }
68
64
69
        return $c->render(
65
        return $c->render(
70
            status  => 200,
66
            status  => 200,
Lines 154-165 sub update { Link Here
154
    my $package_id = $c->param('package_id');
150
    my $package_id = $c->param('package_id');
155
    my $package = Koha::ERM::EHoldings::Packages->find( $package_id );
151
    my $package = Koha::ERM::EHoldings::Packages->find( $package_id );
156
152
157
    unless ($package) {
153
    return $c->render_resource_not_found("Package")
158
        return $c->render(
154
        unless $package;
159
            status  => 404,
160
            openapi => { error => "Package not found" }
161
        );
162
    }
163
155
164
    return try {
156
    return try {
165
        Koha::Database->new->schema->txn_do(
157
        Koha::Database->new->schema->txn_do(
Lines 222-233 sub delete { Link Here
222
    my $c = shift or return;
214
    my $c = shift or return;
223
215
224
    my $package = Koha::ERM::EHoldings::Packages->find( $c->param('package_id') );
216
    my $package = Koha::ERM::EHoldings::Packages->find( $c->param('package_id') );
225
    unless ($package) {
217
226
        return $c->render(
218
    return $c->render_resource_not_found("Package")
227
            status  => 404,
219
        unless $package;
228
            openapi => { error => "Package not found" }
229
        );
230
    }
231
220
232
    return try {
221
    return try {
233
        $package->delete;
222
        $package->delete;
(-)a/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm (-6 / +2 lines)
Lines 63-74 sub get { Link Here
63
        my $resource_id = $c->param('resource_id');
63
        my $resource_id = $c->param('resource_id');
64
        my $resource = $c->objects->find( Koha::ERM::EHoldings::Resources->search, $resource_id );
64
        my $resource = $c->objects->find( Koha::ERM::EHoldings::Resources->search, $resource_id );
65
65
66
        unless ($resource ) {
66
        return $c->render_resource_not_found("eHolding resource")
67
            return $c->render(
67
            unless $resource;
68
                status  => 404,
69
                openapi => { error => "eHolding resource not found" }
70
            );
71
        }
72
68
73
        return $c->render(
69
        return $c->render(
74
            status  => 200,
70
            status  => 200,
(-)a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm (-22 / +8 lines)
Lines 59-70 sub get { Link Here
59
    return try {
59
    return try {
60
        my $title = $c->objects->find( Koha::ERM::EHoldings::Titles->search, $c->param('title_id') );
60
        my $title = $c->objects->find( Koha::ERM::EHoldings::Titles->search, $c->param('title_id') );
61
61
62
        unless ($title ) {
62
        return $c->render_resource_not_found("eHolding title")
63
            return $c->render(
63
            unless $title;
64
                status  => 404,
65
                openapi => { error => "eHolding title not found" }
66
            );
67
        }
68
64
69
        return $c->render(
65
        return $c->render(
70
            status  => 200,
66
            status  => 200,
Lines 153-164 sub update { Link Here
153
149
154
    my $title = Koha::ERM::EHoldings::Titles->find( $c->param('title_id') );
150
    my $title = Koha::ERM::EHoldings::Titles->find( $c->param('title_id') );
155
151
156
    unless ($title) {
152
    return $c->render_resource_not_found("eHolding title")
157
        return $c->render(
153
        unless $title;
158
            status  => 404,
159
            openapi => { error => "eHolding title not found" }
160
        );
161
    }
162
154
163
    return try {
155
    return try {
164
        Koha::Database->new->schema->txn_do(
156
        Koha::Database->new->schema->txn_do(
Lines 218-229 sub delete { Link Here
218
    my $c = shift or return;
210
    my $c = shift or return;
219
211
220
    my $title = Koha::ERM::EHoldings::Titles->find( $c->param('title_id') );
212
    my $title = Koha::ERM::EHoldings::Titles->find( $c->param('title_id') );
221
    unless ($title) {
213
222
        return $c->render(
214
    return $c->render_resource_not_found("eHolding title")
223
            status  => 404,
215
        unless $title;
224
            openapi => { error => "eHolding title not found" }
225
        );
226
    }
227
216
228
    return try {
217
    return try {
229
        $title->delete;
218
        $title->delete;
Lines 252-261 sub import_from_list { Link Here
252
    my $patron = $c->stash('koha.user');
241
    my $patron = $c->stash('koha.user');
253
242
254
    unless ( $list && $list->owner == $c->stash('koha.user')->borrowernumber ) {
243
    unless ( $list && $list->owner == $c->stash('koha.user')->borrowernumber ) {
255
        return $c->render(
244
        return $c->render_resource_not_found("List");
256
            status  => 404,
257
            openapi => { error => "List not found" }
258
        );
259
    }
245
    }
260
246
261
247
(-)a/Koha/REST/V1/ERM/EUsage/CounterFiles.pm (-12 / +4 lines)
Lines 59-70 sub get { Link Here
59
    return try {
59
    return try {
60
        my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
60
        my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
61
61
62
        if ( !$counter_file ) {
62
        return $c->render_resource_not_found("Counter file")
63
            return $c->render(
63
            unless $counter_file;
64
                status  => 404,
65
                openapi => { error => "Counter file not found" }
66
            );
67
        }
68
64
69
        $c->render_file(
65
        $c->render_file(
70
            'data'     => $counter_file->file_content,
66
            'data'     => $counter_file->file_content,
Lines 84-95 sub delete { Link Here
84
80
85
    my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
81
    my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
86
82
87
    unless ($counter_file) {
83
    return $c->render_resource_not_found("Counter file")
88
        return $c->render(
84
        unless $counter_file;
89
            status  => 404,
90
            openapi => { error => "Counter file not found" }
91
        );
92
    }
93
85
94
    return try {
86
    return try {
95
        $counter_file->delete;
87
        $counter_file->delete;
(-)a/Koha/REST/V1/ERM/EUsage/DefaultUsageReports.pm (-6 / +3 lines)
Lines 113-124 sub delete { Link Here
113
    my $c = shift->openapi->valid_input or return;
113
    my $c = shift->openapi->valid_input or return;
114
114
115
    my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find( $c->param('erm_default_usage_report_id') );
115
    my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find( $c->param('erm_default_usage_report_id') );
116
    unless ($default_report) {
116
117
        return $c->render(
117
    return $c->render_resource_not_found("Default report")
118
            status  => 404,
118
        unless $default_report;
119
            openapi => { error => "Default report not found" }
120
        );
121
    }
122
119
123
    return try {
120
    return try {
124
        $default_report->delete;
121
        $default_report->delete;
(-)a/Koha/REST/V1/ERM/EUsage/UsageDataProviders.pm (-30 / +12 lines)
Lines 124-135 sub get { Link Here
124
        my $usage_data_provider =
124
        my $usage_data_provider =
125
            Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
125
            Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
126
126
127
        unless ($usage_data_provider) {
127
        return $c->render_resource_not_found("Usage data provider")
128
            return $c->render(
128
            unless $usage_data_provider;
129
                status  => 404,
130
                openapi => { error => "Usage data provider not found" }
131
            );
132
        }
133
129
134
        return $c->render(
130
        return $c->render(
135
            status  => 200,
131
            status  => 200,
Lines 208-219 sub update { Link Here
208
204
209
    my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
205
    my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
210
206
211
    unless ($usage_data_provider) {
207
    return $c->render_resource_not_found("Usage data provider")
212
        return $c->render(
208
        unless $usage_data_provider;
213
            status  => 404,
214
            openapi => { error => "Usage data provider not found" }
215
        );
216
    }
217
209
218
    return try {
210
    return try {
219
        Koha::Database->new->schema->txn_do(
211
        Koha::Database->new->schema->txn_do(
Lines 265-276 sub delete { Link Here
265
    my $c = shift->openapi->valid_input or return;
257
    my $c = shift->openapi->valid_input or return;
266
258
267
    my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
259
    my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
268
    unless ($usage_data_provider) {
260
269
        return $c->render(
261
    return $c->render_resource_not_found("Usage data provider")
270
            status  => 404,
262
        unless $usage_data_provider;
271
            openapi => { error => "Usage data provider not found" }
272
        );
273
    }
274
263
275
    return try {
264
    return try {
276
        $usage_data_provider->delete;
265
        $usage_data_provider->delete;
Lines 388-399 sub process_SUSHI_response { Link Here
388
377
389
    my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
378
    my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
390
379
391
    unless ($udprovider) {
380
    return $c->render_resource_not_found("Usage data provider")
392
        return $c->render(
381
        unless $udprovider;
393
            status  => 404,
394
            openapi => { error => "Usage data provider not found" }
395
        );
396
    }
397
382
398
    return try {
383
    return try {
399
        my $jobs = $udprovider->enqueue_sushi_harvest_jobs(
384
        my $jobs = $udprovider->enqueue_sushi_harvest_jobs(
Lines 421-432 sub test_connection { Link Here
421
406
422
    my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
407
    my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
423
408
424
    unless ($udprovider) {
409
    return $c->render_resource_not_found("Usage data provider")
425
        return $c->render(
410
        unless $udprovider;
426
            status  => 404,
411
427
            openapi => { error => "Usage data provider not found" }
428
        );
429
    }
430
    try {
412
    try {
431
        my $service_active = $udprovider->test_connection;
413
        my $service_active = $udprovider->test_connection;
432
        return $c->render(
414
        return $c->render(
(-)a/Koha/REST/V1/ERM/Licenses.pm (-18 / +7 lines)
Lines 57-68 sub get { Link Here
57
    return try {
57
    return try {
58
        my $license = $c->objects->find( Koha::ERM::Licenses->search, $c->param('license_id') );
58
        my $license = $c->objects->find( Koha::ERM::Licenses->search, $c->param('license_id') );
59
59
60
        unless ($license) {
60
        return $c->render_resource_not_found("License")
61
            return $c->render(
61
            unless $license;
62
                status  => 404,
63
                openapi => { error => "License not found" }
64
            );
65
        }
66
62
67
        return $c->render(
63
        return $c->render(
68
            status  => 200,
64
            status  => 200,
Lines 158-169 sub update { Link Here
158
154
159
    my $license = Koha::ERM::Licenses->find( $c->param('license_id') );
155
    my $license = Koha::ERM::Licenses->find( $c->param('license_id') );
160
156
161
    unless ($license) {
157
    return $c->render_resource_not_found("License")
162
        return $c->render(
158
        unless $license;
163
            status  => 404,
164
            openapi => { error => "License not found" }
165
        );
166
    }
167
159
168
    return try {
160
    return try {
169
        Koha::Database->new->schema->txn_do(
161
        Koha::Database->new->schema->txn_do(
Lines 230-241 sub delete { Link Here
230
    my $c = shift->openapi->valid_input or return;
222
    my $c = shift->openapi->valid_input or return;
231
223
232
    my $license = Koha::ERM::Licenses->find( $c->param('license_id') );
224
    my $license = Koha::ERM::Licenses->find( $c->param('license_id') );
233
    unless ($license) {
225
234
        return $c->render(
226
    return $c->render_resource_not_found("License")
235
            status  => 404,
227
        unless $license;
236
            openapi => { error => "License not found" }
237
        );
238
    }
239
228
240
    return try {
229
    return try {
241
        $license->delete;
230
        $license->delete;
(-)a/Koha/REST/V1/Holds.pm (-35 / +13 lines)
Lines 106-115 sub add { Link Here
106
            $item = Koha::Items->find($item_id);
106
            $item = Koha::Items->find($item_id);
107
107
108
            unless ($item) {
108
            unless ($item) {
109
                return $c->render(
109
                return $c->render_resource_not_found("Item");
110
                    status  => 404,
111
                    openapi => { error => "item_id not found." }
112
                );
113
            }
110
            }
114
            else {
111
            else {
115
                $biblio = $item->biblio;
112
                $biblio = $item->biblio;
Lines 246-257 sub edit { Link Here
246
    return try {
243
    return try {
247
        my $hold = Koha::Holds->find( $c->param('hold_id') );
244
        my $hold = Koha::Holds->find( $c->param('hold_id') );
248
245
249
        unless ($hold) {
246
        return $c->render_resource_not_found("Hold")
250
            return $c->render(
247
            unless $hold;
251
                status  => 404,
252
                openapi => { error => "Hold not found" }
253
            );
254
        }
255
248
256
        my $overrides = $c->stash('koha.overrides');
249
        my $overrides = $c->stash('koha.overrides');
257
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
250
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
Lines 310-318 sub delete { Link Here
310
303
311
    my $hold = Koha::Holds->find($c->param('hold_id'));
304
    my $hold = Koha::Holds->find($c->param('hold_id'));
312
305
313
    unless ($hold) {
306
    return $c->render_resource_not_found("Hold")
314
        return $c->render( status => 404, openapi => { error => "Hold not found." } );
307
        unless $hold;
315
    }
316
308
317
    return try {
309
    return try {
318
310
Lines 392-400 sub resume { Link Here
392
    my $hold = Koha::Holds->find($c->param('hold_id'));
384
    my $hold = Koha::Holds->find($c->param('hold_id'));
393
    my $body = $c->req->json;
385
    my $body = $c->req->json;
394
386
395
    unless ($hold) {
387
    return $c->render_resource_not_found("Hold")
396
        return $c->render( status => 404, openapi => { error => 'Hold not found.' } );
388
        unless $hold;
397
    }
398
389
399
    return try {
390
    return try {
400
        $hold->resume;
391
        $hold->resume;
Lines 416-427 sub update_priority { Link Here
416
407
417
    my $hold = Koha::Holds->find($c->param('hold_id'));
408
    my $hold = Koha::Holds->find($c->param('hold_id'));
418
409
419
    unless ($hold) {
410
    return $c->render_resource_not_found("Hold")
420
        return $c->render(
411
        unless $hold;
421
            status  => 404,
422
            openapi => { error => "Hold not found" }
423
        );
424
    }
425
412
426
    return try {
413
    return try {
427
        my $priority = $c->req->json;
414
        my $priority = $c->req->json;
Lines 451-462 sub pickup_locations { Link Here
451
438
452
    my $hold = Koha::Holds->find( $c->param('hold_id'), { prefetch => [ 'patron' ] } );
439
    my $hold = Koha::Holds->find( $c->param('hold_id'), { prefetch => [ 'patron' ] } );
453
440
454
    unless ($hold) {
441
    return $c->render_resource_not_found("Hold")
455
        return $c->render(
442
        unless $hold;
456
            status  => 404,
457
            openapi => { error => "Hold not found" }
458
        );
459
    }
460
443
461
    return try {
444
    return try {
462
        my $ps_set;
445
        my $ps_set;
Lines 516-528 sub update_pickup_location { Link Here
516
499
517
    my $hold = Koha::Holds->find($c->param('hold_id'));
500
    my $hold = Koha::Holds->find($c->param('hold_id'));
518
501
519
    unless ($hold) {
502
    return $c->render_resource_not_found("Hold")
520
        return $c->render(
503
        unless $hold;
521
            status  => 404,
522
            openapi => { error => "Hold not found" }
523
        );
524
    }
525
526
504
527
    return try {
505
    return try {
528
506
(-)a/Koha/REST/V1/IllbatchStatuses.pm (-15 / +6 lines)
Lines 54-65 sub get { Link Here
54
54
55
    my $status = Koha::IllbatchStatuses->find( { code => $status_code } );
55
    my $status = Koha::IllbatchStatuses->find( { code => $status_code } );
56
56
57
    if ( not defined $status ) {
57
    return $c->render_resource_not_found("ILL batch status")
58
        return $c->render(
58
        unless $status;
59
            status  => 404,
60
            openapi => { error => "ILL batch status not found" }
61
        );
62
    }
63
59
64
    return $c->render(
60
    return $c->render(
65
        status  => 200,
61
        status  => 200,
Lines 109-120 sub update { Link Here
109
105
110
    my $status = Koha::IllbatchStatuses->find( { code => $c->param('ill_batchstatus_code') } );
106
    my $status = Koha::IllbatchStatuses->find( { code => $c->param('ill_batchstatus_code') } );
111
107
112
    if ( not defined $status ) {
108
    return $c->render_resource_not_found("ILL batch status")
113
        return $c->render(
109
        unless $status;
114
            status  => 404,
115
            openapi => { error => "ILL batch status not found" }
116
        );
117
    }
118
110
119
    my $params = $c->req->json;
111
    my $params = $c->req->json;
120
112
Lines 144-152 sub delete { Link Here
144
136
145
    my $status = Koha::IllbatchStatuses->find( { code => $c->param('ill_batchstatus_code') } );
137
    my $status = Koha::IllbatchStatuses->find( { code => $c->param('ill_batchstatus_code') } );
146
138
147
    if ( not defined $status ) {
139
    return $c->render_resource_not_found("ILL batch status")
148
        return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
140
        unless $status;
149
    }
150
141
151
    if ( $status->is_system ) {
142
    if ( $status->is_system ) {
152
        return $c->render(
143
        return $c->render(
(-)a/Koha/REST/V1/Illbatches.pm (-21 / +8 lines)
Lines 63-74 sub get { Link Here
63
    return try {
63
    return try {
64
        my $ill_batch = $c->objects->find( Koha::Illbatches->new, $c->param('ill_batch_id') );
64
        my $ill_batch = $c->objects->find( Koha::Illbatches->new, $c->param('ill_batch_id') );
65
65
66
        unless ($ill_batch) {
66
        return $c->render_resource_not_found("ILL batch")
67
            return $c->render(
67
            unless $ill_batch;
68
                status  => 404,
69
                openapi => { error => "ILL batch not found" }
70
            );
71
        }
72
68
73
        return $c->render(
69
        return $c->render(
74
            status  => 200,
70
            status  => 200,
Lines 92-103 sub add { Link Here
92
88
93
    my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
89
    my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
94
90
95
    if ( not defined $patron ) {
91
    return $c->render_resource_not_found("Patron")
96
        return $c->render(
92
        unless $patron;
97
            status  => 404,
98
            openapi => { error => "Patron with cardnumber " . $body->{cardnumber} . " not found" }
99
        );
100
    }
101
93
102
    delete $body->{cardnumber};
94
    delete $body->{cardnumber};
103
    $body->{patron_id} = $patron->id;
95
    $body->{patron_id} = $patron->id;
Lines 138-149 sub update { Link Here
138
130
139
    my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') );
131
    my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') );
140
132
141
    unless ($batch) {
133
    return $c->render_resource_not_found("ILL batch")
142
        return $c->render(
134
        unless $batch;
143
            status  => 404,
144
            openapi => { error => "ILL batch not found" }
145
        );
146
    }
147
135
148
    my $params = $c->req->json;
136
    my $params = $c->req->json;
149
    delete $params->{cardnumber};
137
    delete $params->{cardnumber};
Lines 172-180 sub delete { Link Here
172
160
173
    my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') );
161
    my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') );
174
162
175
    if ( not defined $batch ) {
163
    return $c->render_resource_not_found("ILL batch")
176
        return $c->render( status => 404, openapi => { error => "ILL batch not found" } );
164
        unless $batch;
177
    }
178
165
179
    return try {
166
    return try {
180
        $batch->delete_and_log;
167
        $batch->delete_and_log;
(-)a/Koha/REST/V1/ImportBatchProfiles.pm (-10 / +5 lines)
Lines 89-100 sub edit { Link Here
89
89
90
    return try {
90
    return try {
91
        my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
91
        my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
92
        unless ($profile) {
92
93
            return $c->render(
93
        return $c->render_resource_not_found("Import batch profile")
94
                status  => 404,
94
            unless $profile;
95
                openapi => {error => "Import batch profile not found"}
96
            );
97
        }
98
95
99
        $profile->set_from_api($c->req->json)->store;
96
        $profile->set_from_api($c->req->json)->store;
100
97
Lines 119-128 sub delete { Link Here
119
116
120
    my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
117
    my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
121
118
122
    unless ($profile) {
119
    return $c->render_resource_not_found("Import batch profile")
123
        return $c->render( status  => 404,
120
        unless $profile;
124
                        openapi => {error => "Import batch profile not found"} );
125
    }
126
121
127
    return try {
122
    return try {
128
        $profile->delete;
123
        $profile->delete;
(-)a/Koha/REST/V1/ImportRecordMatches.pm (-12 / +6 lines)
Lines 43-54 sub unset_chosen { Link Here
43
    my $matches = Koha::Import::Record::Matches->search({
43
    my $matches = Koha::Import::Record::Matches->search({
44
        import_record_id => $c->param('import_record_id'),
44
        import_record_id => $c->param('import_record_id'),
45
    });
45
    });
46
    unless ($matches) {
46
47
        return $c->render(
47
    return $c->render_resource_not_found("Matches")
48
            status  => 404,
48
        unless $matches;
49
            openapi => { error => "No matches not found" }
49
50
        );
51
    }
52
    return try {
50
    return try {
53
        $matches->update({ chosen => 0 });
51
        $matches->update({ chosen => 0 });
54
        return $c->render( status => 204, openapi => $matches );
52
        return $c->render( status => 204, openapi => $matches );
Lines 80-91 sub set_chosen { Link Here
80
        candidate_match_id => $candidate_match_id
78
        candidate_match_id => $candidate_match_id
81
    });
79
    });
82
80
83
    unless ($match) {
81
    return $c->render_resource_not_found("Match")
84
        return $c->render(
82
        unless $match;
85
            status  => 404,
86
            openapi => { error => "Match not found" }
87
        );
88
    }
89
83
90
    return try {
84
    return try {
91
        my $matches = Koha::Import::Record::Matches->search({
85
        my $matches = Koha::Import::Record::Matches->search({
(-)a/Koha/REST/V1/Items.pm (-48 / +19 lines)
Lines 96-107 sub get { Link Here
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->param('item_id'));
98
        my $item = $c->objects->find($items_rs, $c->param('item_id'));
99
        unless ( $item ) {
99
100
            return $c->render(
100
        return $c->render_resource_not_found("Item")
101
                status => 404,
101
            unless $item;
102
                openapi => { error => 'Item not found'}
102
103
            );
104
        }
105
        return $c->render( status => 200, openapi => $item );
103
        return $c->render( status => 200, openapi => $item );
106
    }
104
    }
107
    catch {
105
    catch {
Lines 120-131 sub delete { Link Here
120
118
121
    return try {
119
    return try {
122
        my $item = Koha::Items->find($c->param('item_id'));
120
        my $item = Koha::Items->find($c->param('item_id'));
123
        unless ( $item ) {
121
124
            return $c->render(
122
        return $c->render_resource_not_found("Item")
125
                status => 404,
123
            unless $item;
126
                openapi => { error => 'Item not found'}
127
            );
128
        }
129
124
130
        my $safe_to_delete = $item->safe_to_delete;
125
        my $safe_to_delete = $item->safe_to_delete;
131
126
Lines 185-196 sub get_bookings { Link Here
185
180
186
    my $item = Koha::Items->find( { itemnumber => $c->param('item_id') }, { prefetch => ['bookings'] } );
181
    my $item = Koha::Items->find( { itemnumber => $c->param('item_id') }, { prefetch => ['bookings'] } );
187
182
188
    unless ($item) {
183
    return $c->render_resource_not_found("Item")
189
        return $c->render(
184
        unless $item;
190
            status  => 404,
191
            openapi => { error => "Object not found." }
192
        );
193
    }
194
185
195
    return try {
186
    return try {
196
187
Lines 218-229 sub pickup_locations { Link Here
218
    my $item_id = $c->param('item_id');
209
    my $item_id = $c->param('item_id');
219
    my $item = Koha::Items->find( $item_id );
210
    my $item = Koha::Items->find( $item_id );
220
211
221
    unless ($item) {
212
    return $c->render_resource_not_found("Item")
222
        return $c->render(
213
        unless $item;
223
            status  => 404,
224
            openapi => { error => "Item not found" }
225
        );
226
    }
227
214
228
    my $patron_id = $c->param('patron_id');
215
    my $patron_id = $c->param('patron_id');
229
    my $patron    = Koha::Patrons->find( $patron_id );
216
    my $patron    = Koha::Patrons->find( $patron_id );
Lines 286-297 sub bundled_items { Link Here
286
    my $item_id = $c->param('item_id');
273
    my $item_id = $c->param('item_id');
287
    my $item = Koha::Items->find( $item_id );
274
    my $item = Koha::Items->find( $item_id );
288
275
289
    unless ($item) {
276
    return $c->render_resource_not_found("Item")
290
        return $c->render(
277
        unless $item;
291
            status  => 404,
292
            openapi => { error => "Item not found" }
293
        );
294
    }
295
278
296
    return try {
279
    return try {
297
        my $items_set = Koha::Items->search(
280
        my $items_set = Koha::Items->search(
Lines 325-336 sub add_to_bundle { Link Here
325
    my $item_id = $c->param('item_id');
308
    my $item_id = $c->param('item_id');
326
    my $item = Koha::Items->find( $item_id );
309
    my $item = Koha::Items->find( $item_id );
327
310
328
    unless ($item) {
311
    return $c->render_resource_not_found("Item")
329
        return $c->render(
312
        unless $item;
330
            status  => 404,
331
            openapi => { error => "Item not found" }
332
        );
333
    }
334
313
335
    my $body = $c->req->json;
314
    my $body = $c->req->json;
336
315
Lines 338-349 sub add_to_bundle { Link Here
338
    $bundle_item_id = barcodedecode($bundle_item_id);
317
    $bundle_item_id = barcodedecode($bundle_item_id);
339
    my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
318
    my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
340
319
341
    unless ($bundle_item) {
320
    return $c->render_resource_not_found("Bundle item")
342
        return $c->render(
321
        unless $bundle_item;
343
            status  => 404,
344
            openapi => { error => "Bundle item not found" }
345
        );
346
    }
347
322
348
    return try {
323
    return try {
349
        my $options = {
324
        my $options = {
Lines 430-441 sub remove_from_bundle { Link Here
430
    my $item_id = $c->param('item_id');
405
    my $item_id = $c->param('item_id');
431
    my $item = Koha::Items->find( $item_id );
406
    my $item = Koha::Items->find( $item_id );
432
407
433
    unless ($item) {
408
    return $c->render_resource_not_found("Item")
434
        return $c->render(
409
        unless $item;
435
            status  => 404,
436
            openapi => { error => "Item not found" }
437
        );
438
    }
439
410
440
    my $bundle_item_id = $c->param('bundled_item_id');
411
    my $bundle_item_id = $c->param('bundled_item_id');
441
    $bundle_item_id = barcodedecode($bundle_item_id);
412
    $bundle_item_id = barcodedecode($bundle_item_id);
(-)a/Koha/REST/V1/Libraries.pm (-27 / +10 lines)
Lines 64-75 sub get { Link Here
64
    return try {
64
    return try {
65
        my $library = Koha::Libraries->find( $c->param('library_id') );
65
        my $library = Koha::Libraries->find( $c->param('library_id') );
66
66
67
        unless ($library) {
67
        return $c->render_resource_not_found("Library")
68
            return $c->render(
68
            unless $library;
69
                status  => 404,
70
                openapi => { error => "Library not found" }
71
            );
72
        }
73
69
74
        return $c->render(
70
        return $c->render(
75
            status  => 200,
71
            status  => 200,
Lines 122-133 sub update { Link Here
122
118
123
    my $library = Koha::Libraries->find( $c->param('library_id') );
119
    my $library = Koha::Libraries->find( $c->param('library_id') );
124
120
125
    if ( not defined $library ) {
121
    return $c->render_resource_not_found("Library")
126
        return $c->render(
122
        unless $library;
127
            status  => 404,
128
            openapi => { error => "Library not found" }
129
        );
130
    }
131
123
132
    return try {
124
    return try {
133
        my $params = $c->req->json;
125
        my $params = $c->req->json;
Lines 155-163 sub delete { Link Here
155
147
156
    my $library = Koha::Libraries->find( $c->param( 'library_id' ) );
148
    my $library = Koha::Libraries->find( $c->param( 'library_id' ) );
157
149
158
    if ( not defined $library ) {
150
    return $c->render_resource_not_found("Library")
159
        return $c->render( status => 404, openapi => { error => "Library not found" } );
151
        unless $library;
160
    }
161
152
162
    return try {
153
    return try {
163
        $library->delete;
154
        $library->delete;
Lines 183-194 sub list_desks { Link Here
183
    return try {
174
    return try {
184
        my $library = Koha::Libraries->find( $c->param('library_id') );
175
        my $library = Koha::Libraries->find( $c->param('library_id') );
185
176
186
        unless ($library) {
177
        return $c->render_resource_not_found("Library")
187
            return $c->render(
178
            unless $library;
188
                status  => 404,
189
                openapi => { error => "Library not found" }
190
            );
191
        }
192
179
193
        return $c->render(
180
        return $c->render(
194
            status  => 200,
181
            status  => 200,
Lines 214-225 sub list_cash_registers { Link Here
214
    return try {
201
    return try {
215
        my $library = Koha::Libraries->find( $c->param('library_id') );
202
        my $library = Koha::Libraries->find( $c->param('library_id') );
216
203
217
        unless ($library) {
204
        return $c->render_resource_not_found("Library")
218
            return $c->render(
205
            unless $library;
219
                status  => 404,
220
                openapi => { error => "Library not found" }
221
            );
222
        }
223
206
224
        return $c->render(
207
        return $c->render(
225
            status  => 200,
208
            status  => 200,
(-)a/Koha/REST/V1/Patrons.pm (-18 / +6 lines)
Lines 79-90 sub get { Link Here
79
        my $patron_id = $c->param('patron_id');
79
        my $patron_id = $c->param('patron_id');
80
        my $patron    = $c->objects->find( Koha::Patrons->search_limited, $patron_id );
80
        my $patron    = $c->objects->find( Koha::Patrons->search_limited, $patron_id );
81
81
82
        unless ($patron) {
82
        return $c->render_resource_not_found("Patron")
83
            return $c->render(
83
            unless $patron;
84
                status  => 404,
85
                openapi => { error => "Patron not found." }
86
            );
87
        }
88
84
89
        return $c->render(
85
        return $c->render(
90
            status  => 200,
86
            status  => 200,
Lines 264-275 sub update { Link Here
264
260
265
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
261
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
266
262
267
    unless ($patron) {
263
    return $c->render_resource_not_found("Patron")
268
         return $c->render(
264
        unless $patron;
269
             status  => 404,
270
             openapi => { error => "Patron not found" }
271
         );
272
     }
273
265
274
    return try {
266
    return try {
275
        my $body = $c->req->json;
267
        my $body = $c->req->json;
Lines 382-393 sub delete { Link Here
382
374
383
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
375
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
384
376
385
    unless ( $patron ) {
377
    return $c->render_resource_not_found("Patron")
386
        return $c->render(
378
        unless $patron;
387
            status  => 404,
388
            openapi => { error => "Patron not found" }
389
        );
390
    }
391
379
392
    return try {
380
    return try {
393
381
(-)a/Koha/REST/V1/Patrons/Account.pm (-30 / +10 lines)
Lines 42-53 sub get { Link Here
42
42
43
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
43
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
44
44
45
    unless ($patron) {
45
    return $c->render_resource_not_found("Patron")
46
        return $c->render(
46
        unless $patron;
47
            status  => 404,
48
            openapi => { error => "Patron not found." }
49
        );
50
    }
51
47
52
    return try {
48
    return try {
53
        my $account = $patron->account;
49
        my $account = $patron->account;
Lines 85-96 sub list_credits { Link Here
85
81
86
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
82
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
87
83
88
    unless ($patron) {
84
    return $c->render_resource_not_found("Patron")
89
        return $c->render(
85
        unless $patron;
90
            status  => 404,
91
            openapi => { error => "Patron not found." }
92
        );
93
    }
94
86
95
    return try {
87
    return try {
96
        my $credits = $c->objects->search( $patron->account->credits );
88
        my $credits = $c->objects->search( $patron->account->credits );
Lines 113-124 sub add_credit { Link Here
113
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
105
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
114
    my $user   = $c->stash('koha.user');
106
    my $user   = $c->stash('koha.user');
115
107
116
    unless ($patron) {
108
    return $c->render_resource_not_found("Patron")
117
        return $c->render(
109
        unless $patron;
118
            status  => 404,
119
            openapi => { error => "Patron not found." }
120
        );
121
    }
122
110
123
    my $account = $patron->account;
111
    my $account = $patron->account;
124
    my $body    = $c->req->json;
112
    my $body    = $c->req->json;
Lines 199-210 sub list_debits { Link Here
199
187
200
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
188
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
201
189
202
    unless ($patron) {
190
    return $c->render_resource_not_found("Patron")
203
        return $c->render(
191
        unless $patron;
204
            status  => 404,
205
            openapi => { error => "Patron not found." }
206
        );
207
    }
208
192
209
    return try {
193
    return try {
210
        my $debits = $c->objects->search( $patron->account->debits );
194
        my $debits = $c->objects->search( $patron->account->debits );
Lines 224-235 sub add_debit { Link Here
224
208
225
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
209
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
226
210
227
    unless ($patron) {
211
    return $c->render_resource_not_found("Patron")
228
        return $c->render(
212
        unless $patron;
229
            status  => 404,
230
            openapi => { error => "Patron not found." }
231
        );
232
    }
233
213
234
    return try {
214
    return try {
235
        my $data =
215
        my $data =
(-)a/Koha/REST/V1/Patrons/Attributes.pm (-56 / +14 lines)
Lines 45-58 sub list_patron_attributes { Link Here
45
45
46
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
46
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
47
47
48
    unless ($patron) {
48
    return $c->render_resource_not_found("Patron")
49
        return $c->render(
49
        unless $patron;
50
            status  => 404,
51
            openapi => {
52
                error => 'Patron not found'
53
            }
54
        );
55
    }
56
50
57
    return try {
51
    return try {
58
52
Lines 79-92 sub add { Link Here
79
73
80
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
74
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
81
75
82
    unless ($patron) {
76
    return $c->render_resource_not_found("Patron")
83
        return $c->render(
77
        unless $patron;
84
            status  => 404,
85
            openapi => {
86
                error => 'Patron not found'
87
            }
88
        );
89
    }
90
78
91
    return try {
79
    return try {
92
80
Lines 151-164 sub overwrite { Link Here
151
139
152
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
140
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
153
141
154
    unless ($patron) {
142
    return $c->render_resource_not_found("Patron")
155
        return $c->render(
143
        unless $patron;
156
            status  => 404,
157
            openapi => {
158
                error => 'Patron not found'
159
            }
160
        );
161
    }
162
144
163
    return try {
145
    return try {
164
146
Lines 229-255 sub update { Link Here
229
211
230
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
212
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
231
213
232
    unless ($patron) {
214
    return $c->render_resource_not_found("Patron")
233
        return $c->render(
215
        unless $patron;
234
            status  => 404,
235
            openapi => {
236
                error => 'Patron not found'
237
            }
238
        );
239
    }
240
216
241
    return try {
217
    return try {
242
        my $attribute = $patron->extended_attributes->find(
218
        my $attribute = $patron->extended_attributes->find(
243
            $c->param('extended_attribute_id') );
219
            $c->param('extended_attribute_id') );
244
220
245
        unless ($attribute) {
221
        return $c->render_resource_not_found("Attribute")
246
            return $c->render(
222
            unless $attribute;
247
                status  => 404,
248
                openapi => {
249
                    error => 'Attribute not found'
250
                }
251
            );
252
        }
253
223
254
        $attribute->set_from_api( $c->req->json )->store;
224
        $attribute->set_from_api( $c->req->json )->store;
255
        $attribute->discard_changes;
225
        $attribute->discard_changes;
Lines 303-330 sub delete { Link Here
303
273
304
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
274
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
305
275
306
    unless ($patron) {
276
    return $c->render_resource_not_found("Patron")
307
        return $c->render(
277
        unless $patron;
308
            status  => 404,
309
            openapi => {
310
                error => 'Patron not found'
311
            }
312
        );
313
    }
314
278
315
    return try {
279
    return try {
316
280
317
        my $attribute = $patron->extended_attributes->find(
281
        my $attribute = $patron->extended_attributes->find(
318
            $c->param('extended_attribute_id') );
282
            $c->param('extended_attribute_id') );
319
283
320
        unless ($attribute) {
284
        return $c->render_resource_not_found("Attribute")
321
            return $c->render(
285
            unless $attribute;
322
                status  => 404,
323
                openapi => {
324
                    error => 'Attribute not found'
325
                }
326
            );
327
        }
328
286
329
        $attribute->delete;
287
        $attribute->delete;
330
        return $c->render(
288
        return $c->render(
(-)a/Koha/REST/V1/Patrons/Holds.pm (-12 / +3 lines)
Lines 40-53 sub list { Link Here
40
40
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
41
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
42
42
43
    unless ( $patron ) {
43
    return $c->render_resource_not_found("Patron")
44
        return $c->render(
44
        unless $patron;
45
            status  => 404,
46
            openapi => {
47
                error => 'Patron not found'
48
            }
49
        );
50
    }
51
45
52
    return try {
46
    return try {
53
47
Lines 79-88 sub delete_public { Link Here
79
        my $hold = $c->objects->find_rs( Koha::Holds->new, $c->param('hold_id') );
73
        my $hold = $c->objects->find_rs( Koha::Holds->new, $c->param('hold_id') );
80
74
81
        unless ( $hold and $c->param('patron_id') == $hold->borrowernumber ) {
75
        unless ( $hold and $c->param('patron_id') == $hold->borrowernumber ) {
82
            return $c->render(
76
            return $c->render_resource_not_found("Hold");
83
                status  => 404,
84
                openapi => { error => 'Object not found' }
85
            );
86
        }
77
        }
87
78
88
        if ( $hold->is_cancelable_from_opac ) {
79
        if ( $hold->is_cancelable_from_opac ) {
(-)a/Koha/REST/V1/Patrons/Password.pm (-3 / +2 lines)
Lines 47-55 sub set { Link Here
47
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
47
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
48
    my $body   = $c->req->json;
48
    my $body   = $c->req->json;
49
49
50
    unless ($patron) {
50
    return $c->render_resource_not_found("Patron")
51
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
51
        unless $patron;
52
    }
53
52
54
    my $password   = $body->{password}   // "";
53
    my $password   = $body->{password}   // "";
55
    my $password_2 = $body->{password_2} // "";
54
    my $password_2 = $body->{password_2} // "";
(-)a/Koha/REST/V1/Patrons/Password/Expiration.pm (-3 / +2 lines)
Lines 45-53 sub set { Link Here
45
45
46
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
46
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
47
47
48
    unless ($patron) {
48
    return $c->render_resource_not_found("Patron")
49
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
49
        unless $patron;
50
    }
51
50
52
    my $body = $c->req->json;
51
    my $body = $c->req->json;
53
52
(-)a/Koha/REST/V1/Preservation/Processings.pm (-18 / +7 lines)
Lines 57-68 sub get { Link Here
57
        my $processing_id = $c->param('processing_id');
57
        my $processing_id = $c->param('processing_id');
58
        my $processing    = $c->objects->find( Koha::Preservation::Processings->search, $processing_id );
58
        my $processing    = $c->objects->find( Koha::Preservation::Processings->search, $processing_id );
59
59
60
        unless ($processing) {
60
        return $c->render_resource_not_found("Processing")
61
            return $c->render(
61
            unless $processing;
62
                status  => 404,
63
                openapi => { error => "Processing not found" }
64
            );
65
        }
66
62
67
        return $c->render(
63
        return $c->render(
68
            status  => 200,
64
            status  => 200,
Lines 144-155 sub update { Link Here
144
    my $processing_id = $c->param('processing_id');
140
    my $processing_id = $c->param('processing_id');
145
    my $processing    = Koha::Preservation::Processings->find($processing_id);
141
    my $processing    = Koha::Preservation::Processings->find($processing_id);
146
142
147
    unless ($processing) {
143
    return $c->render_resource_not_found("Processing")
148
        return $c->render(
144
        unless $processing;
149
            status  => 404,
150
            openapi => { error => "Processing not found" }
151
        );
152
    }
153
145
154
    return try {
146
    return try {
155
        Koha::Database->new->schema->txn_do(
147
        Koha::Database->new->schema->txn_do(
Lines 204-215 sub delete { Link Here
204
196
205
    my $processing_id = $c->param('processing_id');
197
    my $processing_id = $c->param('processing_id');
206
    my $processing    = Koha::Preservation::Processings->find($processing_id);
198
    my $processing    = Koha::Preservation::Processings->find($processing_id);
207
    unless ($processing) {
199
208
        return $c->render(
200
    return $c->render_resource_not_found("Processing")
209
            status  => 404,
201
        unless $processing;
210
            openapi => { error => "Processing not found" }
211
        );
212
    }
213
202
214
    unless ( $processing->can_be_deleted ) {
203
    unless ( $processing->can_be_deleted ) {
215
        return $c->render(
204
        return $c->render(
(-)a/Koha/REST/V1/Preservation/Trains.pm (-72 / +25 lines)
Lines 60-71 sub get { Link Here
60
        my $train_id = $c->param('train_id');
60
        my $train_id = $c->param('train_id');
61
        my $train    = $c->objects->find( Koha::Preservation::Trains->search, $train_id );
61
        my $train    = $c->objects->find( Koha::Preservation::Trains->search, $train_id );
62
62
63
        unless ($train) {
63
        return $c->render_resource_not_found("Train")
64
            return $c->render(
64
            unless $train;
65
                status  => 404,
66
                openapi => { error => "Train not found" }
67
            );
68
        }
69
65
70
        return $c->render(
66
        return $c->render(
71
            status  => 200,
67
            status  => 200,
Lines 144-155 sub update { Link Here
144
    my $train_id = $c->param('train_id');
140
    my $train_id = $c->param('train_id');
145
    my $train    = Koha::Preservation::Trains->find($train_id);
141
    my $train    = Koha::Preservation::Trains->find($train_id);
146
142
147
    unless ($train) {
143
    return $c->render_resource_not_found("Train")
148
        return $c->render(
144
        unless $train;
149
            status  => 404,
150
            openapi => { error => "Train not found" }
151
        );
152
    }
153
145
154
    return try {
146
    return try {
155
        Koha::Database->new->schema->txn_do(
147
        Koha::Database->new->schema->txn_do(
Lines 202-213 sub delete { Link Here
202
    my $c = shift->openapi->valid_input or return;
194
    my $c = shift->openapi->valid_input or return;
203
195
204
    my $train = Koha::Preservation::Trains->find( $c->param('train_id') );
196
    my $train = Koha::Preservation::Trains->find( $c->param('train_id') );
205
    unless ($train) {
197
206
        return $c->render(
198
    return $c->render_resource_not_found("Train")
207
            status  => 404,
199
        unless $train;
208
            openapi => { error => "Train not found" }
209
        );
210
    }
211
200
212
    return try {
201
    return try {
213
        $train->delete;
202
        $train->delete;
Lines 232-243 sub get_item { Link Here
232
    my $train_id = $c->param('train_id');
221
    my $train_id = $c->param('train_id');
233
    my $train    = Koha::Preservation::Trains->find($train_id);
222
    my $train    = Koha::Preservation::Trains->find($train_id);
234
223
235
    unless ($train) {
224
    return $c->render_resource_not_found("Train")
236
        return $c->render(
225
        unless $train;
237
            status  => 404,
238
            openapi => { error => "Train not found" }
239
        );
240
    }
241
226
242
    my $train_item_id = $c->param('train_item_id');
227
    my $train_item_id = $c->param('train_item_id');
243
228
Lines 276-287 sub add_items { Link Here
276
    my $train_id = $c->param('train_id');
261
    my $train_id = $c->param('train_id');
277
    my $train    = Koha::Preservation::Trains->find($train_id);
262
    my $train    = Koha::Preservation::Trains->find($train_id);
278
263
279
    unless ($train) {
264
    return $c->render_resource_not_found("Train")
280
        return $c->render(
265
        unless $train;
281
            status  => 404,
282
            openapi => { error => "Train not found" }
283
        );
284
    }
285
266
286
    my $body = $c->req->json;
267
    my $body = $c->req->json;
287
    return try {
268
    return try {
Lines 317-328 sub add_item { Link Here
317
    my $train_id = $c->param('train_id');
298
    my $train_id = $c->param('train_id');
318
    my $train    = Koha::Preservation::Trains->find($train_id);
299
    my $train    = Koha::Preservation::Trains->find($train_id);
319
300
320
    unless ($train) {
301
    return $c->render_resource_not_found("Train")
321
        return $c->render(
302
        unless $train;
322
            status  => 404,
323
            openapi => { error => "Train not found" }
324
        );
325
    }
326
303
327
    my $body = $c->req->json;
304
    my $body = $c->req->json;
328
    return try {
305
    return try {
Lines 385-408 sub copy_item { Link Here
385
    my $train_id = $c->param('train_id');
362
    my $train_id = $c->param('train_id');
386
    my $train    = Koha::Preservation::Trains->find($train_id);
363
    my $train    = Koha::Preservation::Trains->find($train_id);
387
364
388
    unless ($train) {
365
    return $c->render_resource_not_found("Train")
389
        return $c->render(
366
        unless $train;
390
            status  => 404,
391
            openapi => { error => "Train not found" }
392
        );
393
    }
394
367
395
    my $train_item_id = $c->param('train_item_id');
368
    my $train_item_id = $c->param('train_item_id');
396
369
397
    my $train_item =
370
    my $train_item =
398
        Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
371
        Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
399
372
400
    unless ($train_item) {
373
    return $c->render_resource_not_found("Item")
401
        return $c->render(
374
        unless $train_item;
402
            status  => 404,
403
            openapi => { error => "Item not found" }
404
        );
405
    }
406
375
407
    my $body = $c->req->json;
376
    my $body = $c->req->json;
408
    return try {
377
    return try {
Lines 489-512 sub update_item { Link Here
489
    my $train_id = $c->param('train_id');
458
    my $train_id = $c->param('train_id');
490
    my $train    = Koha::Preservation::Trains->find($train_id);
459
    my $train    = Koha::Preservation::Trains->find($train_id);
491
460
492
    unless ($train) {
461
    return $c->render_resource_not_found("Train")
493
        return $c->render(
462
        unless $train;
494
            status  => 404,
495
            openapi => { error => "Train not found" }
496
        );
497
    }
498
463
499
    my $train_item_id = $c->param('train_item_id');
464
    my $train_item_id = $c->param('train_item_id');
500
465
501
    my $train_item =
466
    my $train_item =
502
        Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
467
        Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
503
468
504
    unless ($train_item) {
469
    return $c->render_resource_not_found("Item")
505
        return $c->render(
470
        unless $train_item;
506
            status  => 404,
507
            openapi => { error => "Item not found" }
508
        );
509
    }
510
471
511
    return try {
472
    return try {
512
        Koha::Database->new->schema->txn_do(
473
        Koha::Database->new->schema->txn_do(
Lines 536-558 sub remove_item { Link Here
536
    my $train_id = $c->param('train_id');
497
    my $train_id = $c->param('train_id');
537
    my $train    = Koha::Preservation::Trains->find($train_id);
498
    my $train    = Koha::Preservation::Trains->find($train_id);
538
499
539
    unless ($train) {
500
    return $c->render_resource_not_found("Train")
540
        return $c->render(
501
        unless $train;
541
            status  => 404,
542
            openapi => { error => "Train not found" }
543
        );
544
    }
545
502
546
    my $train_item_id = $c->param('train_item_id');
503
    my $train_item_id = $c->param('train_item_id');
547
504
548
    my $train_item = $train->items->find($train_item_id);
505
    my $train_item = $train->items->find($train_item_id);
549
506
550
    unless ($train_item) {
507
    return $c->render_resource_not_found("Train item")
551
        return $c->render(
508
        unless $train_item;
552
            status  => 404,
553
            openapi => { error => "Train item not found" }
554
        );
555
    }
556
509
557
    return try {
510
    return try {
558
        $train_item->delete;
511
        $train_item->delete;
(-)a/Koha/REST/V1/Preservation/WaitingList.pm (-6 / +2 lines)
Lines 130-141 sub remove_item { Link Here
130
130
131
        my $item = Koha::Items->find($item_id);
131
        my $item = Koha::Items->find($item_id);
132
132
133
        unless ($item) {
133
        return $c->render_resource_not_found("Item")
134
            return $c->render(
134
            unless $item;
135
                status  => 404,
136
                openapi => { error => "Item not found" }
137
            );
138
        }
139
135
140
        my $not_for_loan_waiting_list_in = C4::Context->preference('PreservationNotForLoanWaitingListIn');
136
        my $not_for_loan_waiting_list_in = C4::Context->preference('PreservationNotForLoanWaitingListIn');
141
        if ( $item->notforloan ne $not_for_loan_waiting_list_in ) {
137
        if ( $item->notforloan ne $not_for_loan_waiting_list_in ) {
(-)a/Koha/REST/V1/Quotes.pm (-14 / +8 lines)
Lines 53-64 sub get { Link Here
53
53
54
    return try {
54
    return try {
55
        my $quote = Koha::Quotes->find( $c->param('quote_id') );
55
        my $quote = Koha::Quotes->find( $c->param('quote_id') );
56
        unless ($quote) {
56
57
            return $c->render(
57
        return $c->render_resource_not_found("Quote")
58
                status  => 404,
58
            unless $quote;
59
                openapi => { error => "quote not found" }
60
            );
61
        }
62
59
63
        return $c->render( status => 200, openapi => $c->objects->to_api($quote), );
60
        return $c->render( status => 200, openapi => $c->objects->to_api($quote), );
64
    }
61
    }
Lines 97-106 sub update { Link Here
97
94
98
    my $quote = Koha::Quotes->find( $c->param('quote_id') );
95
    my $quote = Koha::Quotes->find( $c->param('quote_id') );
99
96
100
    if ( not defined $quote ) {
97
    return $c->render_resource_not_found("Quote")
101
        return $c->render( status  => 404,
98
        unless $quote;
102
                           openapi => { error => "Object not found" } );
103
    }
104
99
105
    return try {
100
    return try {
106
        $quote->set_from_api( $c->req->json );
101
        $quote->set_from_api( $c->req->json );
Lines 120-129 sub delete { Link Here
120
    my $c = shift->openapi->valid_input or return;
115
    my $c = shift->openapi->valid_input or return;
121
116
122
    my $quote = Koha::Quotes->find( $c->param('quote_id') );
117
    my $quote = Koha::Quotes->find( $c->param('quote_id') );
123
    if ( not defined $quote ) {
118
124
        return $c->render( status  => 404,
119
    return $c->render_resource_not_found("Quote")
125
                           openapi => { error => "Object not found" } );
120
        unless $quote;
126
    }
127
121
128
    return try {
122
    return try {
129
        $quote->delete;
123
        $quote->delete;
(-)a/Koha/REST/V1/ReturnClaims.pm (-18 / +8 lines)
Lines 53-62 sub claim_returned { Link Here
53
53
54
        my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } );
54
        my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } );
55
55
56
        return $c->render(
56
        return $c->render_resource_not_found("Checkout")
57
            openapi => { error => "Checkout not found" },
57
            unless $checkout;
58
            status  => 404
59
        ) unless $checkout;
60
58
61
        my $claim = $checkout->claim_returned(
59
        my $claim = $checkout->claim_returned(
62
            {
60
            {
Lines 104-115 sub update_notes { Link Here
104
102
105
    my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
103
    my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
106
104
107
    return $c->render(
105
    return $c->render_resource_not_found("Claim")
108
        status  => 404,
106
        unless $claim;
109
        openapi => {
110
            error => "Claim not found"
111
        }
112
    ) unless $claim;
113
107
114
    return try {
108
    return try {
115
        my $updated_by = $body->{updated_by};
109
        my $updated_by = $body->{updated_by};
Lines 150-159 sub resolve_claim { Link Here
150
144
151
    my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
145
    my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
152
146
153
    return $c->render(
147
    return $c->render_resource_not_found("Claim")
154
        status  => 404,
148
        unless $claim;
155
        openapi => { error => "Claim not found" }
156
    ) unless $claim;
157
149
158
    return try {
150
    return try {
159
151
Lines 195-204 sub delete_claim { Link Here
195
187
196
        my $claim = Koha::Checkouts::ReturnClaims->find( $c->param('claim_id') );
188
        my $claim = Koha::Checkouts::ReturnClaims->find( $c->param('claim_id') );
197
189
198
        return $c->render(
190
        return $c->render_resource_not_found("Claim")
199
            status  => 404,
191
            unless $claim;
200
            openapi => { error => "Claim not found" }
201
        ) unless $claim;
202
192
203
        $claim->delete();
193
        $claim->delete();
204
194
(-)a/Koha/REST/V1/SearchFilter.pm (-12 / +8 lines)
Lines 59-68 Controller function that handles retrieving a single Koha::AdvancedEditorMacro Link Here
59
sub get {
59
sub get {
60
    my $c = shift->openapi->valid_input or return;
60
    my $c = shift->openapi->valid_input or return;
61
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
61
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
62
    unless ($filter) {
62
63
        return $c->render( status  => 404,
63
    return $c->render_resource_not_found("Search filter")
64
                           openapi => { error => "Search filter not found" } );
64
        unless $filter;
65
    }
66
65
67
    return $c->render( status => 200, openapi => $c->objects->to_api($filter), );
66
    return $c->render( status => 200, openapi => $c->objects->to_api($filter), );
68
}
67
}
Lines 107-116 sub update { Link Here
107
106
108
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
107
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
109
108
110
    if ( not defined $filter ) {
109
    return $c->render_resource_not_found("Search filter")
111
        return $c->render( status  => 404,
110
        unless $filter;
112
                           openapi => { error => "Object not found" } );
113
    }
114
111
115
    return try {
112
    return try {
116
        $filter->set_from_api( $c->req->json );
113
        $filter->set_from_api( $c->req->json );
Lines 132-141 sub delete { Link Here
132
    my $c = shift->openapi->valid_input or return;
129
    my $c = shift->openapi->valid_input or return;
133
130
134
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
131
    my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
135
    if ( not defined $filter ) {
132
136
        return $c->render( status  => 404,
133
    return $c->render_resource_not_found("Search filter")
137
                           openapi => { error => "Object not found" } );
134
        unless $filter;
138
    }
139
135
140
    return try {
136
    return try {
141
        $filter->delete;
137
        $filter->delete;
(-)a/Koha/REST/V1/Suggestions.pm (-14 / +6 lines)
Lines 65-76 sub get { Link Here
65
    return try {
65
    return try {
66
        my $suggestion = $c->objects->find( Koha::Suggestions->new, $c->param('suggestion_id') );
66
        my $suggestion = $c->objects->find( Koha::Suggestions->new, $c->param('suggestion_id') );
67
67
68
        unless ($suggestion) {
68
        return $c->render_resource_not_found("Suggestion")
69
            return $c->render(
69
            unless $suggestion;
70
                status  => 404,
71
                openapi => { error => "Suggestion not found." }
72
            );
73
        }
74
70
75
        return $c->render(
71
        return $c->render(
76
            status  => 200,
72
            status  => 200,
Lines 168-177 sub update { Link Here
168
164
169
    my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
165
    my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
170
166
171
    return $c->render(
167
    return $c->render_resource_not_found("Suggestion")
172
        status  => 404,
168
        unless $suggestion;
173
        openapi => { error => 'Suggestion not found.' }
174
    ) unless $suggestion;
175
169
176
    return try {
170
    return try {
177
171
Lines 202-211 sub delete { Link Here
202
196
203
    my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
197
    my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
204
198
205
    return $c->render(
199
    return $c->render_resource_not_found("Suggestion")
206
        status  => 404,
200
        unless $suggestion;
207
        openapi => { error => 'Suggestion not found.' }
208
    ) unless $suggestion;
209
201
210
    return try {
202
    return try {
211
        $suggestion->delete;
203
        $suggestion->delete;
(-)a/Koha/REST/V1/Tickets.pm (-24 / +10 lines)
Lines 56-67 sub get { Link Here
56
56
57
    return try {
57
    return try {
58
        my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
58
        my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
59
        unless ($ticket) {
59
        return $c->render_resource_not_found("Ticket")
60
            return $c->render(
60
            unless $ticket;
61
                status  => 404,
62
                openapi => { error => "Ticket not found" }
63
            );
64
        }
65
61
66
        return $c->render( status => 200, openapi => $c->objects->to_api($ticket), );
62
        return $c->render( status => 200, openapi => $c->objects->to_api($ticket), );
67
    }
63
    }
Lines 109-120 sub update { Link Here
109
105
110
    my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
106
    my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
111
107
112
    if ( not defined $ticket ) {
108
    return $c->render_resource_not_found("Ticket")
113
        return $c->render(
109
        unless $ticket;
114
            status  => 404,
115
            openapi => { error => "Object not found" }
116
        );
117
    }
118
110
119
    return try {
111
    return try {
120
        $ticket->set_from_api( $c->req->json );
112
        $ticket->set_from_api( $c->req->json );
Lines 134-145 sub delete { Link Here
134
    my $c = shift->openapi->valid_input or return;
126
    my $c = shift->openapi->valid_input or return;
135
127
136
    my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
128
    my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
137
    if ( not defined $ticket ) {
129
138
        return $c->render(
130
    return $c->render_resource_not_found("Ticket")
139
            status  => 404,
131
        unless $ticket;
140
            openapi => { error => "Object not found" }
141
        );
142
    }
143
132
144
    return try {
133
    return try {
145
        $ticket->delete;
134
        $ticket->delete;
Lines 162-173 sub list_updates { Link Here
162
151
163
    return try {
152
    return try {
164
        my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
153
        my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
165
        unless ($ticket) {
154
166
            return $c->render(
155
        return $c->render_resource_not_found("Ticket")
167
                status  => 404,
156
            unless $ticket;
168
                openapi => { error => "Ticket not found" }
169
            );
170
        }
171
157
172
        my $updates_set = $ticket->updates;
158
        my $updates_set = $ticket->updates;
173
        my $updates     = $c->objects->search($updates_set);
159
        my $updates     = $c->objects->search($updates_set);
(-)a/t/db_dependent/api/v1/article_requests.t (-3 / +3 lines)
Lines 55-61 subtest 'cancel() tests' => sub { Link Here
55
55
56
    $t->delete_ok(
56
    $t->delete_ok(
57
"//$userid:$password@/api/v1/article_requests/$deleted_article_request_id"
57
"//$userid:$password@/api/v1/article_requests/$deleted_article_request_id"
58
    )->status_is(404)->json_is( { error => "Article request not found" } );
58
    )->status_is(404)->json_is( '/error_code' => 'not_found' );
59
59
60
    my $article_request = $builder->build_object(
60
    my $article_request = $builder->build_object(
61
        {
61
        {
Lines 109-115 subtest 'patron_cancel() tests' => sub { Link Here
109
    # delete non existent article request
109
    # delete non existent article request
110
    $t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/$deleted_article_request_id")
110
    $t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/$deleted_article_request_id")
111
      ->status_is(404)
111
      ->status_is(404)
112
      ->json_is( { error => "Article request not found" } );
112
      ->json_is( '/error_code' => 'not_found' );
113
113
114
    my $another_patron = $builder->build_object({ class => 'Koha::Patrons' });
114
    my $another_patron = $builder->build_object({ class => 'Koha::Patrons' });
115
    my $another_patron_id = $another_patron->id;
115
    my $another_patron_id = $another_patron->id;
Lines 130-136 subtest 'patron_cancel() tests' => sub { Link Here
130
130
131
    $t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/" . $another_article_request->id)
131
    $t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/" . $another_article_request->id)
132
      ->status_is(404)
132
      ->status_is(404)
133
      ->json_is( { error => 'Article request not found' } );
133
      ->json_is( '/error_code' => 'not_found' );
134
134
135
    my $article_request = $builder->build_object(
135
    my $article_request = $builder->build_object(
136
        {
136
        {
(-)a/t/db_dependent/api/v1/authorities.t (-1 / +1 lines)
Lines 108-114 subtest 'get() tests' => sub { Link Here
108
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
108
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
109
                 => { Accept => 'application/marc' } )
109
                 => { Accept => 'application/marc' } )
110
      ->status_is(404)
110
      ->status_is(404)
111
      ->json_is( '/error', 'Object not found.' );
111
      ->json_is( '/error', 'Authority record not found' );
112
112
113
    $schema->storage->txn_rollback;
113
    $schema->storage->txn_rollback;
114
};
114
};
(-)a/t/db_dependent/api/v1/biblios.t (-3 / +3 lines)
Lines 105-111 subtest 'get() tests' => sub { Link Here
105
    $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
105
    $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
106
                 => { Accept => 'application/marc' } )
106
                 => { Accept => 'application/marc' } )
107
      ->status_is(404)
107
      ->status_is(404)
108
      ->json_is( '/error', 'Object not found.' );
108
      ->json_is( '/error', 'Bibliographic record not found' );
109
109
110
    subtest 'marc-in-json encoding tests' => sub {
110
    subtest 'marc-in-json encoding tests' => sub {
111
111
Lines 408-414 subtest 'get_public() tests' => sub { Link Here
408
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber
408
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber
409
                 => { Accept => 'application/marc' } )
409
                 => { Accept => 'application/marc' } )
410
      ->status_is(404)
410
      ->status_is(404)
411
      ->json_is( '/error', 'Object not found.' );
411
      ->json_is( '/error', 'Bibliographic record not found' );
412
412
413
    $schema->storage->txn_rollback;
413
    $schema->storage->txn_rollback;
414
};
414
};
Lines 568-574 subtest 'pickup_locations() tests' => sub { Link Here
568
          . "/pickup_locations?"
568
          . "/pickup_locations?"
569
          . "patron_id=" . $patron->id )
569
          . "patron_id=" . $patron->id )
570
      ->status_is( 404 )
570
      ->status_is( 404 )
571
      ->json_is( '/error' => 'Biblio not found' );
571
      ->json_is( '/error' => 'Bibliographic record not found' );
572
572
573
    $schema->storage->txn_rollback;
573
    $schema->storage->txn_rollback;
574
};
574
};
(-)a/t/db_dependent/api/v1/clubs_holds.t (-1 / +1 lines)
Lines 122-128 subtest 'add() tests' => sub { Link Here
122
                biblio_id         => $non_existent_biblio_id,
122
                biblio_id         => $non_existent_biblio_id,
123
                pickup_library_id => $non_existent_item_homebranch
123
                pickup_library_id => $non_existent_item_homebranch
124
              }
124
              }
125
        )->status_is(404)->json_is( '/error' => 'Biblio not found' );
125
        )->status_is(404)->json_is( '/error' => 'Bibliographic record not found' );
126
126
127
        $t->post_ok(
127
        $t->post_ok(
128
                "//$userid:$password@/api/v1/clubs/"
128
                "//$userid:$password@/api/v1/clubs/"
(-)a/t/db_dependent/api/v1/erm_eholdings_titles.t (-5 / +2 lines)
Lines 309-319 subtest 'add() tests' => sub { Link Here
309
309
310
    # Attempt to import titles from a virtualshelf that doesn't exist
310
    # Attempt to import titles from a virtualshelf that doesn't exist
311
    $virtual_shelf->delete;
311
    $virtual_shelf->delete;
312
    $t->post_ok(
312
    $t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/titles/import" => json => $import_request )
313
    "//$userid:$password@/api/v1/erm/eholdings/local/titles/import" => json =>
313
        ->status_is(404)->json_is( '/error' => 'List not found' );
314
      $import_request )->status_is(404)->json_is(
315
        { error => 'List not found' }
316
      );
317
314
318
    # Authorized attempt to create with null id
315
    # Authorized attempt to create with null id
319
    $ehtitle->{title_id} = undef;
316
    $ehtitle->{title_id} = undef;
(-)a/t/db_dependent/api/v1/jobs.t (-1 / +1 lines)
Lines 141-147 my $job_current = $builder->build_object( Link Here
141
    $job->delete;
141
    $job->delete;
142
    $t->get_ok( "//$superlibrarian_userid:$password@/api/v1/jobs/"
142
    $t->get_ok( "//$superlibrarian_userid:$password@/api/v1/jobs/"
143
          . $job->id )->status_is(404)
143
          . $job->id )->status_is(404)
144
      ->json_is( '/error' => 'Object not found' );
144
      ->json_is( '/error' => 'Job not found' );
145
}
145
}
146
146
147
$schema->storage->txn_rollback;
147
$schema->storage->txn_rollback;
(-)a/t/db_dependent/api/v1/patrons.t (-3 / +2 lines)
Lines 363-371 subtest 'get() tests' => sub { Link Here
363
          ->status_is(200)
363
          ->status_is(200)
364
          ->json_is( '/patron_id' => $patron_1->id );
364
          ->json_is( '/patron_id' => $patron_1->id );
365
365
366
        $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron_2->id )
366
        $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->id )->status_is(404)
367
          ->status_is(404)
367
            ->json_is( '/error' => 'Patron not found' );
368
          ->json_is({ error => "Patron not found." });
369
368
370
        $schema->storage->txn_rollback;
369
        $schema->storage->txn_rollback;
371
    };
370
    };
(-)a/t/db_dependent/api/v1/suggestions.t (-2 / +1 lines)
Lines 153-159 subtest 'get() tests' => sub { Link Here
153
153
154
    $t->get_ok(
154
    $t->get_ok(
155
        "//$userid:$password@/api/v1/suggestions/$non_existent_id")
155
        "//$userid:$password@/api/v1/suggestions/$non_existent_id")
156
      ->status_is(404)->json_is( '/error' => 'Suggestion not found.' );
156
      ->status_is(404)->json_is( '/error' => 'Suggestion not found' );
157
157
158
    $schema->storage->txn_rollback;
158
    $schema->storage->txn_rollback;
159
};
159
};
160
- 

Return to bug 36495