The previous patch introduces some behavioural changes to the API, as
well as the data types that need to be passed; all happens in the tests.
This patch adapts the route so it complies with those changes:
- JSON object containing pickup_library_id attribute is now passed back
and forth.
- The controller should take care of checking the pickup location is
valid, using the available tools.
To test:
1. Apply the patches, up to the tests
2. Run:
$ kshell
k$ prove t/db_dependent/api/v1/holds.t
=> ERROR: Tests fail because the controller doesn't implement the
desired behavior
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
my $c = shift->openapi->valid_input or return;
my $hold_id = $c->validation->param('hold_id');
+ my $body = $c->validation->param('body');
+ my $pickup_library_id = $body->{pickup_library_id};
+
my $hold = Koha::Holds->find($hold_id);
unless ($hold) {
}
return try {
- my $pickup_location = $c->req->json;
- $hold->branchcode($pickup_location)->store;
+ $hold->set_pickup_location({ library_id => $pickup_library_id });
- return $c->render( status => 200, openapi => $pickup_location );
+ return $c->render(
+ status => 200,
+ openapi => {
+ pickup_library_id => $pickup_library_id
+ }
+ );
}
catch {
+
+ if ( blessed $_ and $_->isa('Koha::Exceptions::Hold::InvalidPickupLocation') ) {
+ return $c->render(
+ status => 400,
+ openapi => {
+ error => "$_"
+ }
+ );
+ }
+
$c->unhandled_exception($_);
};
}
"description": "Pickup location",
"required": true,
"schema": {
- "type": "string"
+ "type": "object",
+ "properties": {
+ "pickup_library_id": {
+ "type": "string",
+ "description": "Internal identifier for the pickup library"
+ }
+ }
}
}
],
"200": {
"description": "The new pickup location value for the hold",
"schema": {
- "type": "string"
+ "type": "object",
+ "properties": {
+ "pickup_library_id": {
+ "type": "string",
+ "description": "Internal identifier for the pickup library"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Missing or wrong parameters",
+ "schema": {
+ "$ref": "../definitions.json#/error"
}
},
"401": {