From 3ba3a1c474db72a74c6806f21d3c9b1a58ca3b8f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 19 Aug 2024 09:27:38 -0300 Subject: [PATCH] Bug 37672: Make V1/RecordSources.pm use more helpers This patch adapts the controller class to match the current guidelines by makiing use of the provided helpers. The tests are adapted. Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Paul Derscheid --- Koha/REST/V1/RecordSources.pm | 29 +++++++------------------- t/db_dependent/api/v1/record_sources.t | 2 +- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/Koha/REST/V1/RecordSources.pm b/Koha/REST/V1/RecordSources.pm index 522b6943d3..46ce01b50f 100644 --- a/Koha/REST/V1/RecordSources.pm +++ b/Koha/REST/V1/RecordSources.pm @@ -55,12 +55,8 @@ sub get { return try { my $source = $c->objects->find( Koha::RecordSources->new, $c->param('record_source_id') ); - unless ($source) { - return $c->render( - status => 404, - openapi => { error => "Object not found" } - ); - } + return $c->render_resource_not_found("Record source") + unless $source; return $c->render( status => 200, openapi => $source ); } catch { @@ -97,12 +93,8 @@ sub update { my $source = $c->objects->find_rs( Koha::RecordSources->new, $c->param('record_source_id') ); - unless ($source) { - return $c->render( - status => 404, - openapi => { error => "Object not found" } - ); - } + return $c->render_resource_not_found("Record source") + unless $source; return try { $source->set_from_api( $c->req->json )->store; @@ -122,19 +114,12 @@ sub delete { my $source = $c->objects->find_rs( Koha::RecordSources->new, $c->param('record_source_id') ); - unless ($source) { - return $c->render( - status => 404, - openapi => { error => "Object not found" } - ); - } + return $c->render_resource_not_found("Record source") + unless $source; return try { $source->delete; - return $c->render( - status => 204, - openapi => q{} - ); + return $c->render_resource_deleted; } catch { $c->unhandled_exception($_); }; diff --git a/t/db_dependent/api/v1/record_sources.t b/t/db_dependent/api/v1/record_sources.t index f82264a714..09f3578375 100755 --- a/t/db_dependent/api/v1/record_sources.t +++ b/t/db_dependent/api/v1/record_sources.t @@ -129,7 +129,7 @@ subtest 'get() tests' => sub { $source->delete; $t->get_ok("//$userid:$password@/api/v1/record_sources/$id")->status_is(404) - ->json_is( '/error' => 'Object not found' ); + ->json_is( '/error' => 'Record source not found' ); $schema->storage->txn_rollback; }; -- 2.46.0