Bug 27932: Add GET /biblios/:biblio_id/pickup_locations route
This patch adds the mentioned route. It does so by: - Adding the new path in paths.json - Adding the full route spec in biblios.json - Adds a controller method that takes care of the task To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/api/v1/biblios.t => SUCCESS: Tests pass! 3. Play with your favourite REST tool. Pay special care to the AllowHoldPolicyOverride syspref and the expected behaviors. => SUCCESS: All works as expected 4. Sign off :-D Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
5047557cbf
commit
2db98432d8
|
|
@ -23,6 +23,7 @@ use Koha::Biblios;
|
|||
use Koha::RecordProcessor;
|
||||
use C4::Biblio qw(DelBiblio);
|
||||
|
||||
use List::MoreUtils qw(any);
|
||||
use MARC::Record::MiJ;
|
||||
|
||||
use Try::Tiny;
|
||||
|
|
@ -268,4 +269,75 @@ sub get_items {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 pickup_locations
|
||||
|
||||
Method that returns the possible pickup_locations for a given biblio
|
||||
used for building the dropdown selector
|
||||
|
||||
=cut
|
||||
|
||||
sub pickup_locations {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $biblio_id = $c->validation->param('biblio_id');
|
||||
my $biblio = Koha::Biblios->find( $biblio_id );
|
||||
|
||||
unless ($biblio) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
openapi => { error => "Biblio not found" }
|
||||
);
|
||||
}
|
||||
|
||||
my $patron_id = delete $c->validation->output->{patron_id};
|
||||
my $patron = Koha::Patrons->find( $patron_id );
|
||||
|
||||
unless ($patron) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => { error => "Patron not found" }
|
||||
);
|
||||
}
|
||||
|
||||
return try {
|
||||
|
||||
my $ps_set = $biblio->pickup_locations( { patron => $patron } );
|
||||
|
||||
my $pickup_locations = $c->objects->search( $ps_set );
|
||||
my @response = ();
|
||||
|
||||
if ( C4::Context->preference('AllowHoldPolicyOverride') ) {
|
||||
|
||||
my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } );
|
||||
my $libraries = $c->objects->search($libraries_rs);
|
||||
|
||||
@response = map {
|
||||
my $library = $_;
|
||||
$library->{needs_override} = (
|
||||
any { $_->{library_id} eq $library->{library_id} }
|
||||
@{$pickup_locations}
|
||||
)
|
||||
? Mojo::JSON->false
|
||||
: Mojo::JSON->true;
|
||||
$library;
|
||||
} @{$libraries};
|
||||
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => \@response
|
||||
);
|
||||
}
|
||||
|
||||
@response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations};
|
||||
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => \@response
|
||||
);
|
||||
}
|
||||
catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
"/biblios/{biblio_id}/items": {
|
||||
"$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1items"
|
||||
},
|
||||
"/biblios/{biblio_id}/pickup_locations": {
|
||||
"$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1pickup_locations"
|
||||
},
|
||||
"/cash_registers/{cash_register_id}/cashups": {
|
||||
"$ref": "paths/cash_registers.json#/~1cash_registers~1{cash_register_id}~1cashups"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -232,6 +232,107 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/biblios/{biblio_id}/pickup_locations": {
|
||||
"get": {
|
||||
"x-mojo-to": "Biblios#pickup_locations",
|
||||
"operationId": "getBiblioPickupLocations",
|
||||
"tags": [
|
||||
"biblios",
|
||||
"pickup_locations"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "../parameters.json#/biblio_id_pp"
|
||||
},
|
||||
{
|
||||
"name": "patron_id",
|
||||
"in": "query",
|
||||
"description": "Internal patron identifier",
|
||||
"required": true,
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/match"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/order_by"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/page"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/per_page"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/q_param"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/q_body"
|
||||
},
|
||||
{
|
||||
"$ref": "../parameters.json#/q_header"
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Biblio pickup locations",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "../definitions.json#/library"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Missing or wrong parameters",
|
||||
"schema": {
|
||||
"$ref": "../definitions.json#/error"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Authentication required",
|
||||
"schema": {
|
||||
"$ref": "../definitions.json#/error"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Access forbidden",
|
||||
"schema": {
|
||||
"$ref": "../definitions.json#/error"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Biblio not found",
|
||||
"schema": {
|
||||
"$ref": "../definitions.json#/error"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal server error",
|
||||
"schema": {
|
||||
"$ref": "../definitions.json#/error"
|
||||
}
|
||||
},
|
||||
"503": {
|
||||
"description": "Under maintenance",
|
||||
"schema": {
|
||||
"$ref": "../definitions.json#/error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-koha-authorization": {
|
||||
"permissions": {
|
||||
"reserveforothers": "place_holds"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/public/biblios/{biblio_id}": {
|
||||
"get": {
|
||||
"x-mojo-to": "Biblios#get_public",
|
||||
|
|
|
|||
Loading…
Reference in New Issue