Bug 36495: Use render_resource_not_found() helper everywhere

This patch makes the existing controllers use the new helpers for (most) 404 situations.
The remaining ones are subject to discussion.

To test:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Tomas Cohen Arazi 2024-04-02 18:22:52 +00:00 committed by Katrin Fischer
parent fc7b6d9eb5
commit cd3c5fcce9
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
57 changed files with 392 additions and 1020 deletions

View File

@ -97,12 +97,8 @@ sub get {
my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
unless ($order) {
return $c->render(
status => 404,
openapi => { error => "Order not found" }
);
}
return $c->render_resource_not_found("Order")
unless $order;
return try {
return $c->render(
@ -160,12 +156,8 @@ sub update {
my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
unless ($order) {
return $c->render(
status => 404,
openapi => { error => "Order not found" }
);
}
return $c->render_resource_not_found("Order")
unless $order;
return try {
$order->set_from_api( $c->req->json );
@ -195,10 +187,7 @@ sub delete {
my $order = Koha::Acquisition::Orders->find( $c->param('order_id') );
unless ($order) {
return $c->render(
status => 404,
openapi => { error => 'Order not found' }
);
return $c->render_resource_not_found("Order");
} elsif ( ( $order->orderstatus && $order->orderstatus ne 'cancelled' ) || !$order->datecancellationprinted ) {
# Koha may (historically) have inconsistent order data here (e.g. cancelled without date)
return $c->render(

View File

@ -48,12 +48,8 @@ sub list {
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
unless ($vendor) {
return $c->render(
status => 404,
openapi => { error => "Vendor not found." }
);
}
return $c->render_resource_not_found("Vendor")
unless $vendor;
my $issues_rs = $vendor->issues;
my $issues = $c->objects->search($issues_rs);

View File

@ -63,12 +63,9 @@ sub get {
my $c = shift->openapi->valid_input or return;
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
unless ($vendor) {
return $c->render(
status => 404,
openapi => { error => "Vendor not found" }
);
}
return $c->render_resource_not_found("Vendor")
unless $vendor;
return try {
return $c->render(
@ -114,25 +111,20 @@ Controller function that handles updating a Koha::Acquisition::Bookseller object
sub update {
my $c = shift->openapi->valid_input or return;
my $vendor;
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
return $c->render_resource_not_found("Vendor")
unless $vendor;
return try {
$vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
$vendor->set_from_api( $c->req->json );
$vendor->store();
return $c->render(
status => 200,
openapi => $c->objects->to_api($vendor),
);
}
catch {
if ( not defined $vendor ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
} catch {
$c->unhandled_exception($_);
};
@ -150,12 +142,8 @@ sub delete {
return try {
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
unless ( $vendor ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Vendor")
unless $vendor;
$vendor->delete;

View File

@ -67,12 +67,10 @@ sub get {
my $c = shift->openapi->valid_input or return;
my $patron = $c->stash('koha.user');
my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
unless ($macro) {
return $c->render(
status => 404,
openapi => { error => "Macro not found" }
);
}
return $c->render_resource_not_found("Macro")
unless $macro;
if( $macro->shared ){
return $c->render( status => 403, openapi => {
error => "This macro is shared, you must access it via advanced_editor/macros/shared"
@ -99,10 +97,10 @@ sub get_shared {
my $macro = Koha::AdvancedEditorMacros->find({
id => $c->param('advancededitormacro_id'),
});
unless ($macro) {
return $c->render( status => 404,
openapi => { error => "Macro not found" } );
}
return $c->render_resource_not_found("Macro")
unless $macro;
unless( $macro->shared ){
return $c->render( status => 403, openapi => {
error => "This macro is not shared, you must access it via advanced_editor/macros"
@ -181,10 +179,9 @@ sub update {
my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
if ( not defined $macro ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Macro")
unless $macro;
my $patron = $c->stash('koha.user');
my $body = $c->req->json;
@ -222,10 +219,8 @@ sub update_shared {
my $body = $c->req->json;
if ( not defined $macro ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Macro")
unless $macro;
unless( $macro->shared == 1 || defined $body->{shared} && $body->{shared} == 1 ){
return $c->render( status => 403,
@ -252,10 +247,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
if ( not defined $macro ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Macro")
unless $macro;
my $patron = $c->stash('koha.user');
if( $macro->shared == 1 ){
@ -287,10 +281,9 @@ sub delete_shared {
my $c = shift->openapi->valid_input or return;
my $macro = Koha::AdvancedEditorMacros->find( $c->param('advancededitormacro_id') );
if ( not defined $macro ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Macro")
unless $macro;
unless( $macro->shared == 1 ){
return $c->render( status => 403,

View File

@ -44,12 +44,8 @@ sub cancel {
my $article_request = Koha::ArticleRequests->find( $c->param('article_request_id') );
unless ( $article_request ) {
return $c->render(
status => 404,
openapi => { error => "Article request not found" }
);
}
return $c->render_resource_not_found("Article request")
unless $article_request;
my $reason = $c->param('cancellation_reason');
my $notes = $c->param('notes');
@ -82,23 +78,15 @@ sub patron_cancel {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ( $patron ) {
return $c->render(
status => 404,
openapi => { error => "Patron not found" }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
# patron_id has been validated by the allow-owner check, so the following call to related
# article requests covers the case of article requests not belonging to the patron
my $article_request = $patron->article_requests->find( $c->param('article_request_id') );
unless ( $article_request ) {
return $c->render(
status => 404,
openapi => { error => "Article request not found" }
);
}
return $c->render_resource_not_found("Article request")
unless $article_request;
my $reason = $c->param('cancellation_reason');
my $notes = $c->param('notes');

View File

@ -46,15 +46,8 @@ sub list {
return try {
my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
unless ($provider) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider")
unless $provider;
my $domains_rs = $provider->domains;
return $c->render(
@ -79,29 +72,15 @@ sub get {
my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
unless ($provider) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider")
unless $provider;
my $domains_rs = $provider->domains;
my $domain = $c->objects->find( $domains_rs, $c->param('identity_provider_domain_id') );
unless ($domain) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider domain")
unless $domain;
return $c->render( status => 200, openapi => $domain );
} catch {
@ -164,15 +143,8 @@ sub update {
}
);
unless ($domain) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider domain")
unless $domain;
return try {
@ -209,15 +181,8 @@ sub delete {
}
);
unless ($domain) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider domain")
unless $domain;
return try {
$domain->delete;

View File

@ -68,15 +68,8 @@ sub get {
my $provider = $c->objects->find( Koha::Auth::Identity::Providers->new, $c->param('identity_provider_id') );
unless ( $provider ) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider")
unless $provider;
return $c->render( status => 200, openapi => $provider );
}
@ -148,15 +141,8 @@ sub update {
my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
unless ( $provider ) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider")
unless $provider;
return try {
@ -210,15 +196,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $provider = Koha::Auth::Identity::Providers->find( $c->param('identity_provider_id') );
unless ( $provider ) {
return $c->render(
status => 404,
openapi => {
error => 'Object not found',
error_code => 'not_found',
}
);
}
return $c->render_resource_not_found("Identity provider")
unless $provider;
return try {
$provider->delete;

View File

@ -38,12 +38,8 @@ sub list_av_from_category {
my $category = Koha::AuthorisedValueCategories->find($c->param('authorised_value_category_name'));
unless ($category) {
return $c->render(
status => 404,
openapi => { error => "Category not found" }
);
}
return $c->render_resource_not_found("Category")
unless $category;
return try {
my $av_set = $category->authorised_values->search_with_library_limits;

View File

@ -41,14 +41,9 @@ sub get {
my $c = shift->openapi->valid_input or return;
my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
unless ( $authority ) {
return $c->render(
status => 404,
openapi => {
error => "Object not found."
}
);
}
return $c->render_resource_not_found("Authority record")
unless $authority;
return try {
@ -111,12 +106,8 @@ sub delete {
my $authority = Koha::Authorities->find( { authid => $c->param('authority_id') } );
if ( not defined $authority ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Authority record")
unless $authority;
return try {
DelAuthority( { authid => $authority->authid } );
@ -206,12 +197,8 @@ sub update {
my $authid = $c->param('authority_id');
my $authority = Koha::Authorities->find( { authid => $authid } );
if ( not defined $authority ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Authority record")
unless $authority;
try {
my $headers = $c->req->headers;

View File

@ -75,10 +75,8 @@ sub get {
my $job = Koha::BackgroundJobs->find($job_id);
return $c->render(
status => 404,
openapi => { error => "Object not found" }
) unless $job;
return $c->render_resource_not_found("Job")
unless $job;
return $c->render(
status => 403,

View File

@ -56,14 +56,8 @@ sub get {
my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
unless ( $biblio ) {
return $c->render(
status => 404,
openapi => {
error => "Object not found."
}
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
return try {
@ -128,12 +122,8 @@ sub delete {
my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
if ( not defined $biblio ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
return try {
my $error = DelBiblio( $biblio->id );
@ -166,14 +156,8 @@ sub get_public {
{ biblionumber => $c->param('biblio_id') },
{ prefetch => ['metadata'] } );
unless ($biblio) {
return $c->render(
status => 404,
openapi => {
error => "Object not found."
}
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
return try {
@ -187,14 +171,8 @@ sub get_public {
# unless there's a logged in user, and there's an exception for it's
# category
unless ( $patron and $patron->category->override_hidden_items ) {
if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) )
{
return $c->render(
status => 404,
openapi => {
error => "Object not found."
}
);
if ( $biblio->hidden_in_opac( { rules => $opachiddenitems_rules } ) ) {
return $c->render_resource_not_found("Bibliographic record");
}
}
@ -259,12 +237,8 @@ sub get_bookings {
my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['bookings'] } );
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => "Object not found." }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
return try {
@ -291,12 +265,8 @@ sub get_items {
my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } );
my $bookable_only = $c->param('bookable');
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => "Object not found." }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
return try {
@ -330,12 +300,8 @@ sub add_item {
my $biblio_id = $c->param('biblio_id');
my $biblio = Koha::Biblios->find( $biblio_id );
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => "Biblio not found" }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
my $body = $c->req->json;
@ -443,21 +409,14 @@ sub update_item {
my $biblio_id = $c->param('biblio_id');
my $item_id = $c->param('item_id');
my $biblio = Koha::Biblios->find( { biblionumber => $biblio_id } );
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => "Biblio not found" }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
my $item = $biblio->items->find({ itemnumber => $item_id });
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $item;
my $body = $c->req->json;
@ -501,12 +460,8 @@ sub get_checkouts {
try {
my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => 'Object not found' }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
my $checkouts =
($checked_in)
@ -535,12 +490,8 @@ sub pickup_locations {
my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => "Biblio not found" }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
my $patron = Koha::Patrons->find( $c->param('patron_id') );
$c->req->params->remove('patron_id');
@ -604,14 +555,8 @@ sub get_items_public {
{ prefetch => ['items'] }
);
unless ( $biblio ) {
return $c->render(
status => 404,
openapi => {
error => "Object not found."
}
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
return try {
@ -641,14 +586,8 @@ sub set_rating {
my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
unless ($biblio) {
return $c->render(
status => 404,
openapi => {
error => "Object not found."
}
);
}
$c->render_resource_not_found("Bibliographic record")
unless $biblio;
my $patron = $c->stash('koha.user');
unless ($patron) {
@ -775,12 +714,8 @@ sub update {
my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
if ( ! defined $biblio ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
$c->render_resource_not_found("Bibliographic record")
unless $biblio;
try {
my $headers = $c->req->headers;

View File

@ -206,12 +206,8 @@ sub delete {
}
);
if ( not defined $item_group ) {
return $c->render(
status => 404,
openapi => { error => "Item group not found" }
);
}
return $c->render_resource_not_found("Item group")
unless $item_group;
return try {
$item_group->delete;

View File

@ -45,14 +45,8 @@ sub add {
my $item_group = Koha::Biblio::ItemGroups->find( $c->param('item_group_id') );
unless ( $item_group ) {
return $c->render(
status => 404,
openapi => {
error => 'Item group not found'
}
);
}
return $c->render_resource_not_found("Item group")
unless $item_group;
unless ( $item_group->biblio_id eq $c->param('biblio_id') ) {
return $c->render(

View File

@ -55,12 +55,9 @@ sub get {
return try {
my $booking = $c->objects->find( Koha::Bookings->new, $c->param('booking_id') );
unless ($booking) {
return $c->render(
status => 404,
openapi => { error => "Booking not found" }
);
}
return $c->render_resource_not_found("Booking")
unless $booking;
return $c->render( status => 200, openapi => $booking );
} catch {
@ -115,12 +112,8 @@ sub update {
my $booking = $c->objects->find_rs( Koha::Bookings->new, $c->param('booking_id') );
if ( not defined $booking ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Booking")
unless $booking;
return try {
$booking->set_from_api( $c->req->json );
@ -142,12 +135,8 @@ sub delete {
my $booking = Koha::Bookings->find( $c->param('booking_id') );
unless ( $booking ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Booking")
unless $booking;
return try {
$booking->delete;

View File

@ -71,12 +71,9 @@ sub get {
return try {
my $cashup = Koha::Cash::Register::Cashups->find( $c->param('cashup_id') );
unless ($cashup) {
return $c->render(
status => 404,
openapi => { error => "Cashup not found" }
);
}
return $c->render_resource_not_found("Cashup")
unless $cashup;
return $c->render(
status => 200,

View File

@ -79,16 +79,13 @@ sub get {
my $c = shift->openapi->valid_input or return;
my $checkout_id = $c->param('checkout_id');
my $checkout = Koha::Checkouts->find( $checkout_id );
$checkout = Koha::Old::Checkouts->find( $checkout_id )
unless ($checkout);
unless ($checkout) {
return $c->render(
status => 404,
openapi => { error => "Checkout doesn't exist" }
);
}
my $checkout = Koha::Checkouts->find($checkout_id);
$checkout = Koha::Old::Checkouts->find($checkout_id)
unless $checkout;
return $c->render_resource_not_found("Checkout")
unless $checkout;
return try {
return $c->render(
@ -295,16 +292,13 @@ sub get_renewals {
try {
my $checkout_id = $c->param('checkout_id');
my $checkout = Koha::Checkouts->find($checkout_id);
$checkout = Koha::Old::Checkouts->find($checkout_id)
unless ($checkout);
unless ($checkout) {
return $c->render(
status => 404,
openapi => { error => "Checkout doesn't exist" }
);
}
my $checkout = Koha::Checkouts->find($checkout_id);
$checkout = Koha::Old::Checkouts->find($checkout_id)
unless $checkout;
return $c->render_resource_not_found("Checkout")
unless $checkout;
my $renewals_rs = $checkout->renewals;
my $renewals = $c->objects->search( $renewals_rs );
@ -333,12 +327,8 @@ sub renew {
my $seen = $c->param('seen') || 1;
my $checkout = Koha::Checkouts->find( $checkout_id );
unless ($checkout) {
return $c->render(
status => 404,
openapi => { error => "Checkout doesn't exist" }
);
}
return $c->render_resource_not_found("Checkout")
unless $checkout;
return try {
my ($can_renew, $error) = CanBookBeRenewed($checkout->patron, $checkout);
@ -383,12 +373,8 @@ sub allows_renewal {
my $checkout_id = $c->param('checkout_id');
my $checkout = Koha::Checkouts->find( $checkout_id );
unless ($checkout) {
return $c->render(
status => 404,
openapi => { error => "Checkout doesn't exist" }
);
}
return $c->render_resource_not_found("Checkout")
unless $checkout;
return try {
my ($can_renew, $error) = CanBookBeRenewed($checkout->patron, $checkout);

View File

@ -53,16 +53,13 @@ sub get {
return try {
my $city = Koha::Cities->find( $c->param('city_id') );
unless ($city) {
return $c->render( status => 404,
openapi => { error => "City not found" } );
}
return $c->render_resource_not_found("City")
unless $city;
return $c->render( status => 200, openapi => $c->objects->to_api($city), );
}
catch {
} catch {
$c->unhandled_exception($_);
}
};
}
=head3 add
@ -95,10 +92,8 @@ sub update {
my $city = Koha::Cities->find( $c->param('city_id') );
if ( not defined $city ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("City")
unless $city;
return try {
$city->set_from_api( $c->req->json );
@ -118,10 +113,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $city = Koha::Cities->find( $c->param('city_id') );
if ( not defined $city ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("City")
unless $city;
return try {
$city->delete;

View File

@ -76,10 +76,7 @@ sub add {
my $item = Koha::Items->find($item_id);
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
return $c->render_resource_not_found("Item");
}
else {
$biblio = $item->biblio;
@ -95,12 +92,8 @@ sub add {
);
}
unless ($biblio) {
return $c->render(
status => 404,
openapi => { error => "Biblio not found" }
);
}
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;
my $club_hold = Koha::Club::Hold::add(
{

View File

@ -61,14 +61,8 @@ sub get {
return try {
my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
unless ($smtp_server) {
return $c->render(
status => 404,
openapi => {
error => "SMTP server not found"
}
);
}
return $c->render_resource_not_found("SMTP server")
unless $smtp_server;
return $c->render(
status => 200,
@ -127,14 +121,8 @@ sub update {
my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
if ( not defined $smtp_server ) {
return $c->render(
status => 404,
openapi => {
error => "Object not found"
}
);
}
return $c->render_resource_not_found("SMTP server")
unless $smtp_server;
return try {
$smtp_server->set_from_api( $c->req->json );
@ -171,10 +159,8 @@ sub delete {
my $smtp_server = Koha::SMTP::Servers->find( $c->param('smtp_server_id') );
if ( not defined $smtp_server ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("SMTP server")
unless $smtp_server;
return try {
$smtp_server->delete;

View File

@ -64,12 +64,8 @@ sub get {
return try {
my $agreement = $c->objects->find( Koha::ERM::Agreements->search, $c->param('agreement_id') );
unless ($agreement) {
return $c->render(
status => 404,
openapi => { error => "Agreement not found" }
);
}
return $c->render_resource_not_found("Agreement")
unless $agreement;
return $c->render(
status => 200,
@ -171,12 +167,8 @@ sub update {
my $agreement = Koha::ERM::Agreements->find( $c->param('agreement_id') );
unless ($agreement) {
return $c->render(
status => 404,
openapi => { error => "Agreement not found" }
);
}
return $c->render_resource_not_found("Agreement")
unless $agreement;
return try {
Koha::Database->new->schema->txn_do(
@ -249,12 +241,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $agreement = Koha::ERM::Agreements->find( $c->param('agreement_id') );
unless ($agreement) {
return $c->render(
status => 404,
openapi => { error => "Agreement not found" }
);
}
return $c->render_resource_not_found("Agreement")
unless $agreement;
return try {
$agreement->delete;

View File

@ -42,12 +42,8 @@ sub get {
# Do not use $c->objects->find here, we need the file_content
my $document = Koha::ERM::Documents->find( $c->param('document_id') );
if ( !$document ) {
return $c->render(
status => 404,
openapi => { error => "Document not found" }
);
}
return $c->render_resource_not_found("Document")
unless $document;
$c->render_file('data' => $document->file_content, 'filename' => $document->file_name);
}

View File

@ -59,12 +59,8 @@ sub get {
$package_id
);
unless ($package) {
return $c->render(
status => 404,
openapi => { error => "Package not found" }
);
}
return $c->render_resource_not_found("Package")
unless $package;
return $c->render(
status => 200,
@ -154,12 +150,8 @@ sub update {
my $package_id = $c->param('package_id');
my $package = Koha::ERM::EHoldings::Packages->find( $package_id );
unless ($package) {
return $c->render(
status => 404,
openapi => { error => "Package not found" }
);
}
return $c->render_resource_not_found("Package")
unless $package;
return try {
Koha::Database->new->schema->txn_do(
@ -222,12 +214,9 @@ sub delete {
my $c = shift or return;
my $package = Koha::ERM::EHoldings::Packages->find( $c->param('package_id') );
unless ($package) {
return $c->render(
status => 404,
openapi => { error => "Package not found" }
);
}
return $c->render_resource_not_found("Package")
unless $package;
return try {
$package->delete;

View File

@ -63,12 +63,8 @@ sub get {
my $resource_id = $c->param('resource_id');
my $resource = $c->objects->find( Koha::ERM::EHoldings::Resources->search, $resource_id );
unless ($resource ) {
return $c->render(
status => 404,
openapi => { error => "eHolding resource not found" }
);
}
return $c->render_resource_not_found("eHolding resource")
unless $resource;
return $c->render(
status => 200,

View File

@ -59,12 +59,8 @@ sub get {
return try {
my $title = $c->objects->find( Koha::ERM::EHoldings::Titles->search, $c->param('title_id') );
unless ($title ) {
return $c->render(
status => 404,
openapi => { error => "eHolding title not found" }
);
}
return $c->render_resource_not_found("eHolding title")
unless $title;
return $c->render(
status => 200,
@ -153,12 +149,8 @@ sub update {
my $title = Koha::ERM::EHoldings::Titles->find( $c->param('title_id') );
unless ($title) {
return $c->render(
status => 404,
openapi => { error => "eHolding title not found" }
);
}
return $c->render_resource_not_found("eHolding title")
unless $title;
return try {
Koha::Database->new->schema->txn_do(
@ -218,12 +210,9 @@ sub delete {
my $c = shift or return;
my $title = Koha::ERM::EHoldings::Titles->find( $c->param('title_id') );
unless ($title) {
return $c->render(
status => 404,
openapi => { error => "eHolding title not found" }
);
}
return $c->render_resource_not_found("eHolding title")
unless $title;
return try {
$title->delete;
@ -252,10 +241,7 @@ sub import_from_list {
my $patron = $c->stash('koha.user');
unless ( $list && $list->owner == $c->stash('koha.user')->borrowernumber ) {
return $c->render(
status => 404,
openapi => { error => "List not found" }
);
return $c->render_resource_not_found("List");
}

View File

@ -59,12 +59,8 @@ sub get {
return try {
my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
if ( !$counter_file ) {
return $c->render(
status => 404,
openapi => { error => "Counter file not found" }
);
}
return $c->render_resource_not_found("Counter file")
unless $counter_file;
$c->render_file(
'data' => $counter_file->file_content,
@ -84,12 +80,8 @@ sub delete {
my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
unless ($counter_file) {
return $c->render(
status => 404,
openapi => { error => "Counter file not found" }
);
}
return $c->render_resource_not_found("Counter file")
unless $counter_file;
return try {
$counter_file->delete;

View File

@ -113,12 +113,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find( $c->param('erm_default_usage_report_id') );
unless ($default_report) {
return $c->render(
status => 404,
openapi => { error => "Default report not found" }
);
}
return $c->render_resource_not_found("Default report")
unless $default_report;
return try {
$default_report->delete;

View File

@ -124,12 +124,8 @@ sub get {
my $usage_data_provider =
Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
unless ($usage_data_provider) {
return $c->render(
status => 404,
openapi => { error => "Usage data provider not found" }
);
}
return $c->render_resource_not_found("Usage data provider")
unless $usage_data_provider;
return $c->render(
status => 200,
@ -208,12 +204,8 @@ sub update {
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
unless ($usage_data_provider) {
return $c->render(
status => 404,
openapi => { error => "Usage data provider not found" }
);
}
return $c->render_resource_not_found("Usage data provider")
unless $usage_data_provider;
return try {
Koha::Database->new->schema->txn_do(
@ -265,12 +257,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
unless ($usage_data_provider) {
return $c->render(
status => 404,
openapi => { error => "Usage data provider not found" }
);
}
return $c->render_resource_not_found("Usage data provider")
unless $usage_data_provider;
return try {
$usage_data_provider->delete;
@ -388,12 +377,8 @@ sub process_SUSHI_response {
my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
unless ($udprovider) {
return $c->render(
status => 404,
openapi => { error => "Usage data provider not found" }
);
}
return $c->render_resource_not_found("Usage data provider")
unless $udprovider;
return try {
my $jobs = $udprovider->enqueue_sushi_harvest_jobs(
@ -421,12 +406,9 @@ sub test_connection {
my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
unless ($udprovider) {
return $c->render(
status => 404,
openapi => { error => "Usage data provider not found" }
);
}
return $c->render_resource_not_found("Usage data provider")
unless $udprovider;
try {
my $service_active = $udprovider->test_connection;
return $c->render(

View File

@ -57,12 +57,8 @@ sub get {
return try {
my $license = $c->objects->find( Koha::ERM::Licenses->search, $c->param('license_id') );
unless ($license) {
return $c->render(
status => 404,
openapi => { error => "License not found" }
);
}
return $c->render_resource_not_found("License")
unless $license;
return $c->render(
status => 200,
@ -158,12 +154,8 @@ sub update {
my $license = Koha::ERM::Licenses->find( $c->param('license_id') );
unless ($license) {
return $c->render(
status => 404,
openapi => { error => "License not found" }
);
}
return $c->render_resource_not_found("License")
unless $license;
return try {
Koha::Database->new->schema->txn_do(
@ -230,12 +222,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $license = Koha::ERM::Licenses->find( $c->param('license_id') );
unless ($license) {
return $c->render(
status => 404,
openapi => { error => "License not found" }
);
}
return $c->render_resource_not_found("License")
unless $license;
return try {
$license->delete;

View File

@ -114,10 +114,7 @@ sub add {
$item = Koha::Items->find($item_id);
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "item_id not found." }
);
return $c->render_resource_not_found("Item");
}
else {
$biblio = $item->biblio;
@ -254,12 +251,8 @@ sub edit {
return try {
my $hold = Koha::Holds->find( $c->param('hold_id') );
unless ($hold) {
return $c->render(
status => 404,
openapi => { error => "Hold not found" }
);
}
return $c->render_resource_not_found("Hold")
unless $hold;
my $overrides = $c->stash('koha.overrides');
my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
@ -318,9 +311,8 @@ sub delete {
my $hold = Koha::Holds->find($c->param('hold_id'));
unless ($hold) {
return $c->render( status => 404, openapi => { error => "Hold not found." } );
}
return $c->render_resource_not_found("Hold")
unless $hold;
return try {
@ -400,9 +392,8 @@ sub resume {
my $hold = Koha::Holds->find($c->param('hold_id'));
my $body = $c->req->json;
unless ($hold) {
return $c->render( status => 404, openapi => { error => 'Hold not found.' } );
}
return $c->render_resource_not_found("Hold")
unless $hold;
return try {
$hold->resume;
@ -424,12 +415,8 @@ sub update_priority {
my $hold = Koha::Holds->find($c->param('hold_id'));
unless ($hold) {
return $c->render(
status => 404,
openapi => { error => "Hold not found" }
);
}
return $c->render_resource_not_found("Hold")
unless $hold;
return try {
my $priority = $c->req->json;
@ -459,12 +446,8 @@ sub pickup_locations {
my $hold = Koha::Holds->find( $c->param('hold_id'), { prefetch => [ 'patron' ] } );
unless ($hold) {
return $c->render(
status => 404,
openapi => { error => "Hold not found" }
);
}
return $c->render_resource_not_found("Hold")
unless $hold;
return try {
my $ps_set;
@ -524,13 +507,8 @@ sub update_pickup_location {
my $hold = Koha::Holds->find($c->param('hold_id'));
unless ($hold) {
return $c->render(
status => 404,
openapi => { error => "Hold not found" }
);
}
return $c->render_resource_not_found("Hold")
unless $hold;
return try {

View File

@ -54,12 +54,8 @@ sub get {
my $status = Koha::ILL::Batch::Statuses->find( { code => $status_code } );
if ( not defined $status ) {
return $c->render(
status => 404,
openapi => { error => "ILL batch status not found" }
);
}
return $c->render_resource_not_found("ILL batch status")
unless $status;
return $c->render(
status => 200,
@ -109,12 +105,8 @@ sub update {
my $status = Koha::ILL::Batch::Statuses->find( { code => $c->param('ill_batchstatus_code') } );
if ( not defined $status ) {
return $c->render(
status => 404,
openapi => { error => "ILL batch status not found" }
);
}
return $c->render_resource_not_found("ILL batch status")
unless $status;
my $params = $c->req->json;
@ -144,9 +136,8 @@ sub delete {
my $status = Koha::ILL::Batch::Statuses->find( { code => $c->param('ill_batchstatus_code') } );
if ( not defined $status ) {
return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
}
return $c->render_resource_not_found("ILL batch status")
unless $status;
if ( $status->is_system ) {
return $c->render(

View File

@ -63,12 +63,8 @@ sub get {
return try {
my $ill_batch = $c->objects->find( Koha::ILL::Batches->new, $c->param('ill_batch_id') );
unless ($ill_batch) {
return $c->render(
status => 404,
openapi => { error => "ILL batch not found" }
);
}
return $c->render_resource_not_found("ILL batch")
unless $ill_batch;
return $c->render(
status => 200,
@ -92,12 +88,8 @@ sub add {
my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
if ( not defined $patron ) {
return $c->render(
status => 404,
openapi => { error => "Patron with cardnumber " . $body->{cardnumber} . " not found" }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
delete $body->{cardnumber};
$body->{patron_id} = $patron->id;
@ -138,12 +130,8 @@ sub update {
my $batch = Koha::ILL::Batches->find( $c->param('ill_batch_id') );
unless ($batch) {
return $c->render(
status => 404,
openapi => { error => "ILL batch not found" }
);
}
return $c->render_resource_not_found("ILL batch")
unless $batch;
my $params = $c->req->json;
delete $params->{cardnumber};
@ -172,9 +160,8 @@ sub delete {
my $batch = Koha::ILL::Batches->find( $c->param('ill_batch_id') );
if ( not defined $batch ) {
return $c->render( status => 404, openapi => { error => "ILL batch not found" } );
}
return $c->render_resource_not_found("ILL batch")
unless $batch;
return try {
$batch->delete_and_log;

View File

@ -89,12 +89,9 @@ sub edit {
return try {
my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
unless ($profile) {
return $c->render(
status => 404,
openapi => {error => "Import batch profile not found"}
);
}
return $c->render_resource_not_found("Import batch profile")
unless $profile;
$profile->set_from_api($c->req->json)->store;
@ -119,10 +116,8 @@ sub delete {
my $profile = Koha::ImportBatchProfiles->find( $c->param('import_batch_profile_id') );
unless ($profile) {
return $c->render( status => 404,
openapi => {error => "Import batch profile not found"} );
}
return $c->render_resource_not_found("Import batch profile")
unless $profile;
return try {
$profile->delete;

View File

@ -43,12 +43,10 @@ sub unset_chosen {
my $matches = Koha::Import::Record::Matches->search({
import_record_id => $c->param('import_record_id'),
});
unless ($matches) {
return $c->render(
status => 404,
openapi => { error => "No matches not found" }
);
}
return $c->render_resource_not_found("Matches")
unless $matches;
return try {
$matches->update({ chosen => 0 });
return $c->render( status => 204, openapi => $matches );
@ -80,12 +78,8 @@ sub set_chosen {
candidate_match_id => $candidate_match_id
});
unless ($match) {
return $c->render(
status => 404,
openapi => { error => "Match not found" }
);
}
return $c->render_resource_not_found("Match")
unless $match;
return try {
my $matches = Koha::Import::Record::Matches->search({

View File

@ -96,12 +96,10 @@ sub get {
try {
my $items_rs = Koha::Items->new;
my $item = $c->objects->find($items_rs, $c->param('item_id'));
unless ( $item ) {
return $c->render(
status => 404,
openapi => { error => 'Item not found'}
);
}
return $c->render_resource_not_found("Item")
unless $item;
return $c->render( status => 200, openapi => $item );
}
catch {
@ -120,12 +118,9 @@ sub delete {
return try {
my $item = Koha::Items->find($c->param('item_id'));
unless ( $item ) {
return $c->render(
status => 404,
openapi => { error => 'Item not found'}
);
}
return $c->render_resource_not_found("Item")
unless $item;
my $safe_to_delete = $item->safe_to_delete;
@ -185,12 +180,8 @@ sub get_bookings {
my $item = Koha::Items->find( { itemnumber => $c->param('item_id') }, { prefetch => ['bookings'] } );
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Object not found." }
);
}
return $c->render_resource_not_found("Item")
unless $item;
return try {
@ -218,12 +209,8 @@ sub pickup_locations {
my $item_id = $c->param('item_id');
my $item = Koha::Items->find( $item_id );
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $item;
my $patron_id = $c->param('patron_id');
my $patron = Koha::Patrons->find( $patron_id );
@ -286,12 +273,8 @@ sub bundled_items {
my $item_id = $c->param('item_id');
my $item = Koha::Items->find( $item_id );
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $item;
return try {
my $items_set = Koha::Items->search(
@ -325,12 +308,8 @@ sub add_to_bundle {
my $item_id = $c->param('item_id');
my $item = Koha::Items->find( $item_id );
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $item;
my $body = $c->req->json;
@ -338,12 +317,8 @@ sub add_to_bundle {
$bundle_item_id = barcodedecode($bundle_item_id);
my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
unless ($bundle_item) {
return $c->render(
status => 404,
openapi => { error => "Bundle item not found" }
);
}
return $c->render_resource_not_found("Bundle item")
unless $bundle_item;
return try {
my $options = {
@ -430,12 +405,8 @@ sub remove_from_bundle {
my $item_id = $c->param('item_id');
my $item = Koha::Items->find( $item_id );
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $item;
my $bundle_item_id = $c->param('bundled_item_id');
$bundle_item_id = barcodedecode($bundle_item_id);

View File

@ -64,12 +64,8 @@ sub get {
return try {
my $library = Koha::Libraries->find( $c->param('library_id') );
unless ($library) {
return $c->render(
status => 404,
openapi => { error => "Library not found" }
);
}
return $c->render_resource_not_found("Library")
unless $library;
return $c->render(
status => 200,
@ -122,12 +118,8 @@ sub update {
my $library = Koha::Libraries->find( $c->param('library_id') );
if ( not defined $library ) {
return $c->render(
status => 404,
openapi => { error => "Library not found" }
);
}
return $c->render_resource_not_found("Library")
unless $library;
return try {
my $params = $c->req->json;
@ -155,9 +147,8 @@ sub delete {
my $library = Koha::Libraries->find( $c->param( 'library_id' ) );
if ( not defined $library ) {
return $c->render( status => 404, openapi => { error => "Library not found" } );
}
return $c->render_resource_not_found("Library")
unless $library;
return try {
$library->delete;
@ -183,12 +174,8 @@ sub list_desks {
return try {
my $library = Koha::Libraries->find( $c->param('library_id') );
unless ($library) {
return $c->render(
status => 404,
openapi => { error => "Library not found" }
);
}
return $c->render_resource_not_found("Library")
unless $library;
return $c->render(
status => 200,
@ -214,12 +201,8 @@ sub list_cash_registers {
return try {
my $library = Koha::Libraries->find( $c->param('library_id') );
unless ($library) {
return $c->render(
status => 404,
openapi => { error => "Library not found" }
);
}
return $c->render_resource_not_found("Library")
unless $library;
return $c->render(
status => 200,

View File

@ -79,12 +79,8 @@ sub get {
my $patron_id = $c->param('patron_id');
my $patron = $c->objects->find( Koha::Patrons->search_limited, $patron_id );
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found." }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return $c->render(
status => 200,
@ -264,12 +260,8 @@ sub update {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found" }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $body = $c->req->json;
@ -382,12 +374,8 @@ sub delete {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ( $patron ) {
return $c->render(
status => 404,
openapi => { error => "Patron not found" }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {

View File

@ -42,12 +42,8 @@ sub get {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found." }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $account = $patron->account;
@ -85,12 +81,8 @@ sub list_credits {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found." }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $credits = $c->objects->search( $patron->account->credits );
@ -113,12 +105,8 @@ sub add_credit {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
my $user = $c->stash('koha.user');
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found." }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
my $account = $patron->account;
my $body = $c->req->json;
@ -199,12 +187,8 @@ sub list_debits {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found." }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $debits = $c->objects->search( $patron->account->debits );
@ -224,12 +208,8 @@ sub add_debit {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => { error => "Patron not found." }
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $data =

View File

@ -45,14 +45,8 @@ sub list_patron_attributes {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => {
error => 'Patron not found'
}
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
@ -79,14 +73,8 @@ sub add {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => {
error => 'Patron not found'
}
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
@ -151,14 +139,8 @@ sub overwrite {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => {
error => 'Patron not found'
}
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
@ -229,27 +211,15 @@ sub update {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => {
error => 'Patron not found'
}
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $attribute = $patron->extended_attributes->find(
$c->param('extended_attribute_id') );
unless ($attribute) {
return $c->render(
status => 404,
openapi => {
error => 'Attribute not found'
}
);
}
return $c->render_resource_not_found("Attribute")
unless $attribute;
$attribute->set_from_api( $c->req->json )->store;
$attribute->discard_changes;
@ -303,28 +273,16 @@ sub delete {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render(
status => 404,
openapi => {
error => 'Patron not found'
}
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $attribute = $patron->extended_attributes->find(
$c->param('extended_attribute_id') );
unless ($attribute) {
return $c->render(
status => 404,
openapi => {
error => 'Attribute not found'
}
);
}
return $c->render_resource_not_found("Attribute")
unless $attribute;
$attribute->delete;
return $c->render(

View File

@ -40,14 +40,8 @@ sub list {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ( $patron ) {
return $c->render(
status => 404,
openapi => {
error => 'Patron not found'
}
);
}
return $c->render_resource_not_found("Patron")
unless $patron;
my $old = $c->param('old');
$c->req->params->remove('old');
@ -81,10 +75,7 @@ sub delete_public {
my $hold = $c->objects->find_rs( Koha::Holds->new, $c->param('hold_id') );
unless ( $hold and $c->param('patron_id') == $hold->borrowernumber ) {
return $c->render(
status => 404,
openapi => { error => 'Object not found' }
);
return $c->render_resource_not_found("Hold");
}
if ( $hold->is_cancelable_from_opac ) {

View File

@ -47,9 +47,8 @@ sub set {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
my $body = $c->req->json;
unless ($patron) {
return $c->render( status => 404, openapi => { error => "Patron not found." } );
}
return $c->render_resource_not_found("Patron")
unless $patron;
my $password = $body->{password} // "";
my $password_2 = $body->{password_2} // "";

View File

@ -45,9 +45,8 @@ sub set {
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ($patron) {
return $c->render( status => 404, openapi => { error => "Patron not found." } );
}
return $c->render_resource_not_found("Patron")
unless $patron;
my $body = $c->req->json;

View File

@ -57,12 +57,8 @@ sub get {
my $processing_id = $c->param('processing_id');
my $processing = $c->objects->find( Koha::Preservation::Processings->search, $processing_id );
unless ($processing) {
return $c->render(
status => 404,
openapi => { error => "Processing not found" }
);
}
return $c->render_resource_not_found("Processing")
unless $processing;
return $c->render(
status => 200,
@ -144,12 +140,8 @@ sub update {
my $processing_id = $c->param('processing_id');
my $processing = Koha::Preservation::Processings->find($processing_id);
unless ($processing) {
return $c->render(
status => 404,
openapi => { error => "Processing not found" }
);
}
return $c->render_resource_not_found("Processing")
unless $processing;
return try {
Koha::Database->new->schema->txn_do(
@ -204,12 +196,9 @@ sub delete {
my $processing_id = $c->param('processing_id');
my $processing = Koha::Preservation::Processings->find($processing_id);
unless ($processing) {
return $c->render(
status => 404,
openapi => { error => "Processing not found" }
);
}
return $c->render_resource_not_found("Processing")
unless $processing;
unless ( $processing->can_be_deleted ) {
return $c->render(

View File

@ -60,12 +60,8 @@ sub get {
my $train_id = $c->param('train_id');
my $train = $c->objects->find( Koha::Preservation::Trains->search, $train_id );
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
return $c->render(
status => 200,
@ -144,12 +140,8 @@ sub update {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
return try {
Koha::Database->new->schema->txn_do(
@ -202,12 +194,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $train = Koha::Preservation::Trains->find( $c->param('train_id') );
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
return try {
$train->delete;
@ -232,12 +221,8 @@ sub get_item {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
my $train_item_id = $c->param('train_item_id');
@ -276,12 +261,8 @@ sub add_items {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
my $body = $c->req->json;
return try {
@ -317,12 +298,8 @@ sub add_item {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
my $body = $c->req->json;
return try {
@ -385,24 +362,16 @@ sub copy_item {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
my $train_item_id = $c->param('train_item_id');
my $train_item =
Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
unless ($train_item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $train_item;
my $body = $c->req->json;
return try {
@ -489,24 +458,16 @@ sub update_item {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
my $train_item_id = $c->param('train_item_id');
my $train_item =
Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
unless ($train_item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $train_item;
return try {
Koha::Database->new->schema->txn_do(
@ -536,23 +497,15 @@ sub remove_item {
my $train_id = $c->param('train_id');
my $train = Koha::Preservation::Trains->find($train_id);
unless ($train) {
return $c->render(
status => 404,
openapi => { error => "Train not found" }
);
}
return $c->render_resource_not_found("Train")
unless $train;
my $train_item_id = $c->param('train_item_id');
my $train_item = $train->items->find($train_item_id);
unless ($train_item) {
return $c->render(
status => 404,
openapi => { error => "Train item not found" }
);
}
return $c->render_resource_not_found("Train item")
unless $train_item;
return try {
$train_item->delete;

View File

@ -130,12 +130,8 @@ sub remove_item {
my $item = Koha::Items->find($item_id);
unless ($item) {
return $c->render(
status => 404,
openapi => { error => "Item not found" }
);
}
return $c->render_resource_not_found("Item")
unless $item;
my $not_for_loan_waiting_list_in = C4::Context->preference('PreservationNotForLoanWaitingListIn');
if ( $item->notforloan ne $not_for_loan_waiting_list_in ) {

View File

@ -53,12 +53,9 @@ sub get {
return try {
my $quote = Koha::Quotes->find( $c->param('quote_id') );
unless ($quote) {
return $c->render(
status => 404,
openapi => { error => "quote not found" }
);
}
return $c->render_resource_not_found("Quote")
unless $quote;
return $c->render( status => 200, openapi => $c->objects->to_api($quote), );
}
@ -97,10 +94,8 @@ sub update {
my $quote = Koha::Quotes->find( $c->param('quote_id') );
if ( not defined $quote ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Quote")
unless $quote;
return try {
$quote->set_from_api( $c->req->json );
@ -120,10 +115,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $quote = Koha::Quotes->find( $c->param('quote_id') );
if ( not defined $quote ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Quote")
unless $quote;
return try {
$quote->delete;

View File

@ -53,10 +53,8 @@ sub claim_returned {
my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } );
return $c->render(
openapi => { error => "Checkout not found" },
status => 404
) unless $checkout;
return $c->render_resource_not_found("Checkout")
unless $checkout;
my $claim = $checkout->claim_returned(
{
@ -104,12 +102,8 @@ sub update_notes {
my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
return $c->render(
status => 404,
openapi => {
error => "Claim not found"
}
) unless $claim;
return $c->render_resource_not_found("Claim")
unless $claim;
return try {
my $updated_by = $body->{updated_by};
@ -150,10 +144,8 @@ sub resolve_claim {
my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
return $c->render(
status => 404,
openapi => { error => "Claim not found" }
) unless $claim;
return $c->render_resource_not_found("Claim")
unless $claim;
return try {
@ -195,10 +187,8 @@ sub delete_claim {
my $claim = Koha::Checkouts::ReturnClaims->find( $c->param('claim_id') );
return $c->render(
status => 404,
openapi => { error => "Claim not found" }
) unless $claim;
return $c->render_resource_not_found("Claim")
unless $claim;
$claim->delete();

View File

@ -59,10 +59,9 @@ Controller function that handles retrieving a single Koha::AdvancedEditorMacro
sub get {
my $c = shift->openapi->valid_input or return;
my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
unless ($filter) {
return $c->render( status => 404,
openapi => { error => "Search filter not found" } );
}
return $c->render_resource_not_found("Search filter")
unless $filter;
return $c->render( status => 200, openapi => $c->objects->to_api($filter), );
}
@ -107,10 +106,8 @@ sub update {
my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
if ( not defined $filter ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Search filter")
unless $filter;
return try {
$filter->set_from_api( $c->req->json );
@ -132,10 +129,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $filter = Koha::SearchFilters->find( $c->param('search_filter_id') );
if ( not defined $filter ) {
return $c->render( status => 404,
openapi => { error => "Object not found" } );
}
return $c->render_resource_not_found("Search filter")
unless $filter;
return try {
$filter->delete;

View File

@ -65,12 +65,8 @@ sub get {
return try {
my $suggestion = $c->objects->find( Koha::Suggestions->new, $c->param('suggestion_id') );
unless ($suggestion) {
return $c->render(
status => 404,
openapi => { error => "Suggestion not found." }
);
}
return $c->render_resource_not_found("Suggestion")
unless $suggestion;
return $c->render(
status => 200,
@ -168,10 +164,8 @@ sub update {
my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
return $c->render(
status => 404,
openapi => { error => 'Suggestion not found.' }
) unless $suggestion;
return $c->render_resource_not_found("Suggestion")
unless $suggestion;
return try {
@ -202,10 +196,8 @@ sub delete {
my $suggestion = Koha::Suggestions->find( $c->param('suggestion_id') );
return $c->render(
status => 404,
openapi => { error => 'Suggestion not found.' }
) unless $suggestion;
return $c->render_resource_not_found("Suggestion")
unless $suggestion;
return try {
$suggestion->delete;

View File

@ -56,12 +56,8 @@ sub get {
return try {
my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
unless ($ticket) {
return $c->render(
status => 404,
openapi => { error => "Ticket not found" }
);
}
return $c->render_resource_not_found("Ticket")
unless $ticket;
return $c->render( status => 200, openapi => $c->objects->to_api($ticket), );
}
@ -109,12 +105,8 @@ sub update {
my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
if ( not defined $ticket ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Ticket")
unless $ticket;
return try {
$ticket->set_from_api( $c->req->json );
@ -134,12 +126,9 @@ sub delete {
my $c = shift->openapi->valid_input or return;
my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
if ( not defined $ticket ) {
return $c->render(
status => 404,
openapi => { error => "Object not found" }
);
}
return $c->render_resource_not_found("Ticket")
unless $ticket;
return try {
$ticket->delete;
@ -162,12 +151,9 @@ sub list_updates {
return try {
my $ticket = Koha::Tickets->find( $c->param('ticket_id') );
unless ($ticket) {
return $c->render(
status => 404,
openapi => { error => "Ticket not found" }
);
}
return $c->render_resource_not_found("Ticket")
unless $ticket;
my $updates_set = $ticket->updates;
my $updates = $c->objects->search($updates_set);

View File

@ -55,7 +55,7 @@ subtest 'cancel() tests' => sub {
$t->delete_ok(
"//$userid:$password@/api/v1/article_requests/$deleted_article_request_id"
)->status_is(404)->json_is( { error => "Article request not found" } );
)->status_is(404)->json_is( '/error_code' => 'not_found' );
my $article_request = $builder->build_object(
{
@ -109,7 +109,7 @@ subtest 'patron_cancel() tests' => sub {
# delete non existent article request
$t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/$deleted_article_request_id")
->status_is(404)
->json_is( { error => "Article request not found" } );
->json_is( '/error_code' => 'not_found' );
my $another_patron = $builder->build_object({ class => 'Koha::Patrons' });
my $another_patron_id = $another_patron->id;
@ -130,7 +130,7 @@ subtest 'patron_cancel() tests' => sub {
$t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/" . $another_article_request->id)
->status_is(404)
->json_is( { error => 'Article request not found' } );
->json_is( '/error_code' => 'not_found' );
my $article_request = $builder->build_object(
{

View File

@ -108,7 +108,7 @@ subtest 'get() tests' => sub {
$t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
=> { Accept => 'application/marc' } )
->status_is(404)
->json_is( '/error', 'Object not found.' );
->json_is( '/error', 'Authority record not found' );
$schema->storage->txn_rollback;
};

View File

@ -105,7 +105,7 @@ subtest 'get() tests' => sub {
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
=> { Accept => 'application/marc' } )
->status_is(404)
->json_is( '/error', 'Object not found.' );
->json_is( '/error', 'Bibliographic record not found' );
subtest 'marc-in-json encoding tests' => sub {
@ -447,7 +447,7 @@ subtest 'get_public() tests' => sub {
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber
=> { Accept => 'application/marc' } )
->status_is(404)
->json_is( '/error', 'Object not found.' );
->json_is( '/error', 'Bibliographic record not found' );
$schema->storage->txn_rollback;
};
@ -607,7 +607,7 @@ subtest 'pickup_locations() tests' => sub {
. "/pickup_locations?"
. "patron_id=" . $patron->id )
->status_is( 404 )
->json_is( '/error' => 'Biblio not found' );
->json_is( '/error' => 'Bibliographic record not found' );
$schema->storage->txn_rollback;
};

View File

@ -122,7 +122,7 @@ subtest 'add() tests' => sub {
biblio_id => $non_existent_biblio_id,
pickup_library_id => $non_existent_item_homebranch
}
)->status_is(404)->json_is( '/error' => 'Biblio not found' );
)->status_is(404)->json_is( '/error' => 'Bibliographic record not found' );
$t->post_ok(
"//$userid:$password@/api/v1/clubs/"

View File

@ -309,11 +309,8 @@ subtest 'add() tests' => sub {
# Attempt to import titles from a virtualshelf that doesn't exist
$virtual_shelf->delete;
$t->post_ok(
"//$userid:$password@/api/v1/erm/eholdings/local/titles/import" => json =>
$import_request )->status_is(404)->json_is(
{ error => 'List not found' }
);
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/titles/import" => json => $import_request )
->status_is(404)->json_is( '/error' => 'List not found' );
# Authorized attempt to create with null id
$ehtitle->{title_id} = undef;

View File

@ -141,7 +141,7 @@ my $job_current = $builder->build_object(
$job->delete;
$t->get_ok( "//$superlibrarian_userid:$password@/api/v1/jobs/"
. $job->id )->status_is(404)
->json_is( '/error' => 'Object not found' );
->json_is( '/error' => 'Job not found' );
}
$schema->storage->txn_rollback;

View File

@ -363,9 +363,8 @@ subtest 'get() tests' => sub {
->status_is(200)
->json_is( '/patron_id' => $patron_1->id );
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron_2->id )
->status_is(404)
->json_is({ error => "Patron not found." });
$t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->id )->status_is(404)
->json_is( '/error' => 'Patron not found' );
$schema->storage->txn_rollback;
};

View File

@ -153,7 +153,7 @@ subtest 'get() tests' => sub {
$t->get_ok(
"//$userid:$password@/api/v1/suggestions/$non_existent_id")
->status_is(404)->json_is( '/error' => 'Suggestion not found.' );
->status_is(404)->json_is( '/error' => 'Suggestion not found' );
$schema->storage->txn_rollback;
};