Skip to content

Commit

Permalink
Exclude suspended holds from queue length by default.
Browse files Browse the repository at this point in the history
Suspended holds can be included by including query parameter include_suspended_in_hold_queue=1.

Closes #33.
  • Loading branch information
EreMaijala committed Jun 20, 2024
1 parent be2435a commit ac12aa3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Koha/Plugin/Fi/KohaSuomi/DI/AvailabilityController.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ sub biblio_hold {
my $ignore_patron_holds = $c->validation->param('ignore_patron_holds');
my $limit_items = $c->validation->param('limit_items');
my $include_found_in_hold_queue = $c->validation->param('include_found_in_hold_queue');
my $include_suspended_in_hold_queue = $c->validation->param('include_suspended_in_hold_queue');

return try {
my $patron = Koha::Patrons->find($borrowernumber);
Expand All @@ -106,6 +107,7 @@ sub biblio_hold {
$params->{'query_pickup_locations'} = 1 if $query_pickup_locations;
$params->{'ignore_patron_holds'} = 1 if $ignore_patron_holds;
$params->{'include_found_in_hold_queue'} = 1 if $include_found_in_hold_queue;
$params->{'include_suspended_in_hold_queue'} = 1 if $include_suspended_in_hold_queue;
$params->{'to_branch'} = $to_branch if $to_branch;
$params->{'limit'} = $limit_items if $limit_items;

Expand Down Expand Up @@ -140,6 +142,7 @@ sub biblio_search {

my $biblionumber = $c->validation->param('biblio_id');
my $include_found_in_hold_queue = $c->validation->param('include_found_in_hold_queue');
my $include_suspended_in_hold_queue = $c->validation->param('include_suspended_in_hold_queue');

return try {
my $availability = undef;
Expand All @@ -148,6 +151,7 @@ sub biblio_search {
biblio => $biblio,
};
$params->{'include_found_in_hold_queue'} = 1 if $include_found_in_hold_queue;
$params->{'include_suspended_in_hold_queue'} = 1 if $include_suspended_in_hold_queue;
$availability = Koha::Plugin::Fi::KohaSuomi::DI::Koha::Availability::Search->biblio($params);
return $c->render(status => 200, openapi => $availability->in_opac->to_api);
}
Expand Down Expand Up @@ -257,6 +261,7 @@ sub item_hold {
my $query_pickup_locations = $c->validation->param('query_pickup_locations');
my $to_branch = $c->validation->param('library_id');
my $include_found_in_hold_queue = $c->validation->param('include_found_in_hold_queue');
my $include_suspended_in_hold_queue = $c->validation->param('include_suspended_in_hold_queue');

return try {
my $patron = Koha::Patrons->find($borrowernumber);
Expand All @@ -272,6 +277,7 @@ sub item_hold {
$params->{'to_branch'} = $to_branch;
}
$params->{'include_found_in_hold_queue'} = 1 if $include_found_in_hold_queue;
$params->{'include_suspended_in_hold_queue'} = 1 if $include_suspended_in_hold_queue;

my $availability = undef;
if (my $item = Koha::Items->find($itemnumber)) {
Expand Down
8 changes: 7 additions & 1 deletion Koha/Plugin/Fi/KohaSuomi/DI/Koha/Biblio/Availability.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ sub new {

# Optionally include found holds in hold queue length calculation.
$self->{'include_found_in_hold_queue'} = $params->{'include_found_in_hold_queue'};


# Optionally include suspended holds in hold queue length calculation.
$self->{'include_suspended_in_hold_queue'} = $params->{'include_suspended_in_hold_queue'};

if (exists $params->{'biblio'}) {
unless (ref($params->{'biblio'}) eq 'Koha::Biblio') {
Koha::Plugin::Fi::KohaSuomi::DI::Koha::Exceptions::BadParameter->throw(
Expand Down Expand Up @@ -199,6 +202,9 @@ sub get_hold_queue_length
if (!$self->{'include_found_in_hold_queue'}) {
$hold_params->{found} = undef;
}
if (!$self->{'include_suspended_in_hold_queue'}) {
$hold_params->{suspend} = 0;
}
return Koha::Holds->search($hold_params)->count;
}

Expand Down
6 changes: 6 additions & 0 deletions Koha/Plugin/Fi/KohaSuomi/DI/Koha/Item/Availability.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ sub new {
# Optionally include found holds in hold queue length calculation.
$self->{'include_found_in_hold_queue'} = $params->{'include_found_in_hold_queue'};

# Optionally include suspended holds in hold queue length calculation.
$self->{'include_suspended_in_hold_queue'} = $params->{'include_suspended_in_hold_queue'};

if (exists $params->{'item'}) {
unless (ref($params->{'item'}) eq 'Koha::Item') {
Koha::Plugin::Fi::KohaSuomi::DI::Koha::Exceptions::BadParameter->throw(
Expand Down Expand Up @@ -200,6 +203,9 @@ sub get_hold_queue_length
if (!$self->{'include_found_in_hold_queue'}) {
$hold_params->{found} = undef;
}
if (!$self->{'include_suspended_in_hold_queue'}) {
$hold_params->{suspend} = 0;
}
return Koha::Holds->search($hold_params)->count;
}

Expand Down
15 changes: 15 additions & 0 deletions Koha/Plugin/Fi/KohaSuomi/DI/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ paths:
name: include_found_in_hold_queue
required: false
type: integer
- description: "Whether to include suspended holds in hold queue length. 1 = yes, 0 or no parameter = no."
in: query
name: include_suspended_in_hold_queue
required: false
type: integer
produces:
- application/json
responses:
Expand Down Expand Up @@ -217,6 +222,11 @@ paths:
name: include_found_in_hold_queue
required: false
type: integer
- description: "Whether to include suspended holds in hold queue length. 1 = yes, 0 or no parameter = no."
in: query
name: include_suspended_in_hold_queue
required: false
type: integer
produces:
- application/json
responses:
Expand Down Expand Up @@ -358,6 +368,11 @@ paths:
name: include_found_in_hold_queue
required: false
type: integer
- description: "Whether to include suspended holds in hold queue length. 1 = yes, 0 or no parameter = no."
in: query
name: include_suspended_in_hold_queue
required: false
type: integer
produces:
- application/json
responses:
Expand Down
12 changes: 11 additions & 1 deletion Koha/Plugin/Fi/KohaSuomi/sample_requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ Authorization: Bearer {{token}}
GET {{baseUrl}}/contrib/kohasuomi/availability/biblios/2/hold?patron_id=57&include_found_in_hold_queue=0 HTTP/1.1
Authorization: Bearer {{token}}

###
# @name hold_availability_suspended_included
GET {{baseUrl}}/contrib/kohasuomi/availability/biblios/2/hold?patron_id=57&include_suspended_in_hold_queue=1 HTTP/1.1
Authorization: Bearer {{token}}

###
# @name item_hold_availability
GET {{baseUrl}}/contrib/kohasuomi/availability/items/30/hold?patron_id=57&include_found_in_hold_queue=1 HTTP/1.1
GET {{baseUrl}}/contrib/kohasuomi/availability/items/154/hold?patron_id=57&include_found_in_hold_queue=1 HTTP/1.1
Authorization: Bearer {{token}}

###
# @name item_hold_availability_suspended_included
GET {{baseUrl}}/contrib/kohasuomi/availability/items/154/hold?patron_id=57&include_found_in_hold_queue=1&include_suspended_in_hold_queue=1 HTTP/1.1
Authorization: Bearer {{token}}

###
Expand Down

0 comments on commit ac12aa3

Please sign in to comment.