Browse Source

Bug 16271: Allow more filters on /api/v1/holds

borrowernumber parameter is no longer required and you can filter on
every column of reserves table

Some example requests
- GET /api/v1/holds
- GET /api/v1/holds?biblionumber=123
- GET /api/v1/holds?borrowernumber=456
- GET /api/v1/holds?priority=0&found=W

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Julian Maurice 7 years ago
committed by Kyle M Hall
parent
commit
975be0aef0
  1. 14
      Koha/REST/V1/Hold.pm
  2. 103
      api/v1/swagger.json
  3. 19
      t/db_dependent/api/v1/holds.t

14
Koha/REST/V1/Hold.pm

@ -23,20 +23,20 @@ use C4::Biblio;
use C4::Reserves;
use Koha::Patrons;
use Koha::Holds;
use Koha::DateUtils;
sub list {
my ($c, $args, $cb) = @_;
my $borrowernumber = $c->param('borrowernumber');
my $borrower = Koha::Patrons->find($borrowernumber);
unless ($borrower) {
return $c->$cb({error => "Borrower not found"}, 404);
my $params = $c->req->query_params->to_hash;
my @valid_params = Koha::Holds->_resultset->result_source->columns;
foreach my $key (keys %$params) {
delete $params->{$key} unless grep { $key eq $_ } @valid_params;
}
my $holds = Koha::Holds->search($params)->unblessed;
my @reserves = C4::Reserves::GetReservesFromBorrowernumber($borrowernumber);
return $c->$cb(\@reserves, 200);
return $c->$cb($holds, 200);
}
sub add {

103
api/v1/swagger.json

@ -79,12 +79,113 @@
"operationId": "listHolds",
"tags": ["borrowers", "holds"],
"parameters": [
{
"name": "reserve_id",
"in": "query",
"description": "Internal reserve identifier",
"type": "integer"
},
{
"name": "borrowernumber",
"in": "query",
"description": "Internal borrower identifier",
"required": true,
"type": "integer"
},
{
"name": "reservedate",
"in": "query",
"description": "Reserve date",
"type": "string"
},
{
"name": "biblionumber",
"in": "query",
"description": "Internal biblio identifier",
"type": "integer"
},
{
"name": "branchcode",
"in": "query",
"description": "Branch code",
"type": "string"
},
{
"name": "notificationdate",
"in": "query",
"description": "Notification date",
"type": "string"
},
{
"name": "reminderdate",
"in": "query",
"description": "Reminder date",
"type": "string"
},
{
"name": "cancellationdate",
"in": "query",
"description": "Cancellation date",
"type": "string"
},
{
"name": "reservenotes",
"in": "query",
"description": "Reserve notes",
"type": "string"
},
{
"name": "priority",
"in": "query",
"description": "Priority",
"type": "integer"
},
{
"name": "found",
"in": "query",
"description": "Found status",
"type": "string"
},
{
"name": "timestamp",
"in": "query",
"description": "Time of latest update",
"type": "string"
},
{
"name": "itemnumber",
"in": "query",
"description": "Internal item identifier",
"type": "integer"
},
{
"name": "waitingdate",
"in": "query",
"description": "Date the item was marked as waiting for the patron",
"type": "string"
},
{
"name": "expirationdate",
"in": "query",
"description": "Date the hold expires",
"type": "string"
},
{
"name": "lowestPriority",
"in": "query",
"description": "Lowest priority",
"type": "integer"
},
{
"name": "suspend",
"in": "query",
"description": "Suspended",
"type": "integer"
},
{
"name": "suspend_until",
"in": "query",
"description": "Suspended until",
"type": "string"
}
],
"produces": ["application/json"],

19
t/db_dependent/api/v1/holds.t

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 30;
use Test::More tests => 39;
use Test::Mojo;
use DateTime;
@ -56,6 +56,8 @@ my $borrowernumber2 = $borrower2->borrowernumber;
my $biblionumber = create_biblio('RESTful Web APIs');
my $itemnumber = create_item($biblionumber, 'TEST000001');
$dbh->do('DELETE FROM reserves');
my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber,
$biblionumber, undef, 1, undef, undef, undef, '', $itemnumber);
@ -63,6 +65,17 @@ my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber,
C4::Reserves::AddReserve($branchcode, $borrowernumber2,
$biblionumber, undef, 2, undef, undef, undef, '', $itemnumber);
$t->get_ok('/api/v1/holds')
->status_is(200)
->json_has('/0')
->json_has('/1')
->json_hasnt('/2');
$t->get_ok('/api/v1/holds?priority=2')
->status_is(200)
->json_is('/0/borrowernumber', $borrowernumber2)
->json_hasnt('/1');
my $suspend_until = DateTime->now->add(days => 10)->ymd;
my $put_data = {
priority => 2,
@ -92,8 +105,8 @@ $t->get_ok("/api/v1/holds?borrowernumber=$borrowernumber")
my $inexisting_borrowernumber = $borrowernumber2 + 1;
$t->get_ok("/api/v1/holds?borrowernumber=$inexisting_borrowernumber")
->status_is(404)
->json_has('/error');
->status_is(200)
->json_is([]);
$dbh->do('DELETE FROM issuingrules');
$dbh->do(q{

Loading…
Cancel
Save