Bug 18409: Make the controller for holds use Koha::Holds
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 21 Apr 2017 23:34:00 +0000 (20:34 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 24 Apr 2017 13:40:40 +0000 (09:40 -0400)
Recently, there's been a major fix on the REST api swagger spec,
which involved fixing boolean values so they are actually booleans
and Koha::Object was extended to handle that.
While the swagger spec for this endpoint got fixed, such is not the case
with the implementation (the controller class).

This patch fixes this situation by:
- Specifying boolean properties as boolean in the schema file
- Fixes the controller so it returns Koha::Hold objects instead of the
  hashref returned by GetReserve, which is wrong.
- Better (than empty) descriptions are added to 'suspend',
  'suspend_until' and 'lowestPriority' on the spec.

To test:
- Run:
  $ sudo koha-shell kohadev
 k$ cd kohaclone
 k$ prove t/db_dependent/api/v1/holds.t
=> FAIL: Tests fail, mostly due to error 500 results.
- Apply this patch
- Run:
 k$ prove t/db_dependent/api/v1/holds.t
=> SUCCESS: Tests pass!
- Sign off :-D

This can also be tested using any interface for REST apis.

Note: This endpoint lacks several of the new guidelines and is not
complete (there's no GET for single holds, etc). It is also missing
exception handling. There are probably
other bug reports for that, just thought it was worth mentioning.

Followed test plan and this patch worked as intended
Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>

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

Koha/REST/V1/Hold.pm
Koha/Schema/Result/Reserve.pm
api/v1/swagger/definitions/hold.json

index 7f0b1ff..d72e5df 100644 (file)
@@ -34,7 +34,7 @@ sub list {
     foreach my $key (keys %$params) {
         delete $params->{$key} unless grep { $key eq $_ } @valid_params;
     }
-    my $holds = Koha::Holds->search($params)->unblessed;
+    my $holds = Koha::Holds->search($params);
 
     return $c->$cb($holds, 200);
 }
@@ -106,7 +106,7 @@ sub add {
         }, 500);
     }
 
-    my $reserve = C4::Reserves::GetReserve($reserve_id);
+    my $reserve = Koha::Holds->find($reserve_id);
 
     return $c->$cb($reserve, 201);
 }
@@ -137,8 +137,9 @@ sub edit {
         rank => $priority,
         suspend_until => $suspend_until,
     };
+
     C4::Reserves::ModReserve($params);
-    $reserve = C4::Reserves::GetReserve($reserve_id);
+    $reserve = Koha::Holds->find($reserve_id);
 
     return $c->$cb($reserve, 200);
 }
index 4d56006..eb5d07f 100644 (file)
@@ -334,4 +334,9 @@ __PACKAGE__->belongs_to(
   },
 );
 
+__PACKAGE__->add_columns(
+    '+lowestPriority' => { is_boolean => 1 },
+    '+suspend' => { is_boolean => 1 }
+);
+
 1;
index 5f41318..8f91aed 100644 (file)
     },
     "lowestPriority": {
       "type": "boolean",
-      "description": ""
+      "description": "Controls if the hold is given the lowest priority on the queue"
     },
     "suspend": {
       "type": "boolean",
-      "description": ""
+      "description": "Controls if the hold is suspended"
     },
     "suspend_until": {
       "type": ["string", "null"],
-      "description": ""
+      "description": "Date until which the hold has been suspended"
     },
     "itemtype": {
       "type": ["string", "null"],