From 0727b8ae886c3554b9dbb7394f4a919d2ce0b700 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 9 Oct 2023 15:54:54 +0000 Subject: [PATCH] Bug 30719: QA follow-up: Rewrite ill batches get endpoint --- Koha/REST/V1/Illbatches.pm | 37 ++++++++++----------------- api/v1/swagger/paths/ill_batches.yaml | 20 +++++++++++++++ t/db_dependent/api/v1/ill_batches.t | 3 ++- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Koha/REST/V1/Illbatches.pm b/Koha/REST/V1/Illbatches.pm index b8edbc815e..9cc6e56808 100644 --- a/Koha/REST/V1/Illbatches.pm +++ b/Koha/REST/V1/Illbatches.pm @@ -56,34 +56,25 @@ Get one batch =cut sub get { - my $c = shift->openapi->valid_input; + my $c = shift->openapi->valid_input or return; - my $batchid = $c->param('ill_batch_id'); + return try { + my $ill_batch = $c->objects->find( Koha::Illbatches->search, $c->param('ill_batch_id') ); - my $batch = Koha::Illbatches->find($batchid); + unless ($ill_batch) { + return $c->render( + status => 404, + openapi => { error => "ILL batch not found" } + ); + } - if ( not defined $batch ) { return $c->render( - status => 404, - openapi => { error => "ILL batch not found" } + status => 200, + openapi => $ill_batch ); - } - - return $c->render( - status => 200, - openapi => { - batch_id => $batch->id, - backend => $batch->backend, - library_id => $batch->branchcode, - name => $batch->name, - statuscode => $batch->statuscode, - patron_id => $batch->borrowernumber, - patron => $batch->patron->unblessed, - branch => $batch->branch->unblessed, - status => $batch->status->unblessed, - requests_count => $batch->requests_count - } - ); + } catch { + $c->unhandled_exception($_); + }; } =head3 add diff --git a/api/v1/swagger/paths/ill_batches.yaml b/api/v1/swagger/paths/ill_batches.yaml index caada10af8..4eb5f0cf23 100644 --- a/api/v1/swagger/paths/ill_batches.yaml +++ b/api/v1/swagger/paths/ill_batches.yaml @@ -127,6 +127,26 @@ description: ILL batch id/name/contents required: true type: string + - $ref: "../swagger.yaml#/parameters/page" + - $ref: "../swagger.yaml#/parameters/per_page" + - $ref: "../swagger.yaml#/parameters/match" + - $ref: "../swagger.yaml#/parameters/order_by" + - $ref: "../swagger.yaml#/parameters/q_param" + - $ref: "../swagger.yaml#/parameters/q_body" + - $ref: "../swagger.yaml#/parameters/request_id_header" + - name: x-koha-embed + in: header + required: false + description: Embed list sent as a request header + type: array + items: + type: string + enum: + - +strings + - requests+count + - patron + - branch + collectionFormat: csv produces: - application/json responses: diff --git a/t/db_dependent/api/v1/ill_batches.t b/t/db_dependent/api/v1/ill_batches.t index b658ee36c1..e7f5d74445 100755 --- a/t/db_dependent/api/v1/ill_batches.t +++ b/t/db_dependent/api/v1/ill_batches.t @@ -161,7 +161,8 @@ subtest 'get() tests' => sub { $patron->set_password( { password => $password, skip_validation => 1 } ); my $unauth_userid = $patron->userid; - $t->get_ok( "//$userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(200) + $t->get_ok( "//$userid:$password@/api/v1/ill/batches/" + . $batch->id => { 'x-koha-embed' => '+strings,requests+count,patron,branch' } )->status_is(200) ->json_has( '/batch_id', 'Batch ID' )->json_has( '/name', 'Batch name' ) ->json_has( '/backend', 'Backend name' )->json_has( '/patron_id', 'Borrowernumber' ) ->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' ) -- 2.30.2