Bug 30719: DB and API
- Adds 'batch' accessor to Illrequest object - New illbatches and illbatch_statuses tables - New foreign key 'batch_id' in illrequests table - Atomic update file - Default illbatch_statuses - Add 'add' ill_requests api method - Add POST method in ill_requests path - Add 'batch_id property to ill_request api definition - Updated swagger.yml with new batches and batchstatuses endpoints Co-authored-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> Signed-off-by: Edith Speller <Edith.Speller@ukhsa.gov.uk> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
1cabc0ed67
commit
5bf5860370
|
|
@ -35,6 +35,7 @@ use Koha::Illrequestattributes;
|
|||
use Koha::AuthorisedValue;
|
||||
use Koha::Illrequest::Logger;
|
||||
use Koha::Patron;
|
||||
use Koha::Illbatches;
|
||||
use Koha::AuthorisedValues;
|
||||
use Koha::Biblios;
|
||||
use Koha::Items;
|
||||
|
|
@ -146,6 +147,20 @@ sub push_processor {
|
|||
push @{$self->{processors}}, $processor;
|
||||
}
|
||||
|
||||
=head3 batch
|
||||
|
||||
my $batch = $request->batch;
|
||||
|
||||
Returns the batch associated with a request
|
||||
|
||||
=cut
|
||||
|
||||
sub batch {
|
||||
my ( $self ) = @_;
|
||||
|
||||
return Koha::Illbatches->find($self->_result->batch_id);
|
||||
}
|
||||
|
||||
=head3 statusalias
|
||||
|
||||
my $statusalias = $request->statusalias;
|
||||
|
|
@ -1979,6 +1994,18 @@ sub strings_map {
|
|||
};
|
||||
}
|
||||
|
||||
my $batch = $self->batch;
|
||||
if ($batch) {
|
||||
$strings->{"batch"} = {
|
||||
id => $batch->id,
|
||||
name => $batch->name,
|
||||
backend => $batch->backend,
|
||||
borrowernumber => $batch->borrowernumber,
|
||||
branchcode => $batch->branchcode,
|
||||
statuscode => $batch->statuscode
|
||||
};
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ use Koha::Patrons;
|
|||
use Koha::Libraries;
|
||||
use Koha::DateUtils qw( format_sqldatetime );
|
||||
|
||||
use Scalar::Util qw( blessed );
|
||||
use Try::Tiny qw( catch try );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::REST::V1::Illrequests
|
||||
|
|
@ -55,4 +58,88 @@ sub list {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 add
|
||||
|
||||
Adds a new ILL request
|
||||
|
||||
=cut
|
||||
|
||||
sub add {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
return try {
|
||||
|
||||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
$body->{backend} = delete $body->{ill_backend_id};
|
||||
$body->{borrowernumber} = delete $body->{patron_id};
|
||||
$body->{branchcode} = delete $body->{library_id};
|
||||
|
||||
my $request = Koha::Illrequest->new->load_backend( $body->{backend} );
|
||||
|
||||
my $create_api = $request->_backend->capabilities('create_api');
|
||||
|
||||
if (!$create_api) {
|
||||
return $c->render(
|
||||
status => 405,
|
||||
openapi => {
|
||||
errors => [ 'This backend does not allow request creation via API' ]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
my $create_result = &{$create_api}($body, $request);
|
||||
my $new_id = $create_result->illrequest_id;
|
||||
|
||||
my @new_req = Koha::Illrequests->search({
|
||||
illrequest_id => $new_id
|
||||
})->as_list;
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $new_req[0]->illrequest_id);
|
||||
return $c->render(
|
||||
status => 201,
|
||||
openapi => $new_req[0]->to_api
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
|
||||
my $to_api_mapping = Koha::Illrequest->new->to_api_mapping;
|
||||
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
|
||||
return $c->render(
|
||||
status => 409,
|
||||
openapi => { error => $_->error, conflict => $_->duplicate_id }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->broken_fk }
|
||||
. " does not exist"
|
||||
}
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->parameter }
|
||||
. " does not exist"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ properties:
|
|||
- integer
|
||||
- "null"
|
||||
description: Internal bibliographic record identifier
|
||||
batch_id:
|
||||
type:
|
||||
- integer
|
||||
- "null"
|
||||
description: Batch id this requests belongs to
|
||||
patron_id:
|
||||
type:
|
||||
- integer
|
||||
|
|
@ -115,6 +120,11 @@ properties:
|
|||
- array
|
||||
- "null"
|
||||
description: The linked extended ill request attributes (x-koha-embed)
|
||||
batch:
|
||||
type:
|
||||
- object
|
||||
- "null"
|
||||
description: The linked ill batch object (x-koha-embed)
|
||||
library:
|
||||
type:
|
||||
- object
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
- comments
|
||||
- comments+count
|
||||
- extended_attributes
|
||||
- batch
|
||||
- library
|
||||
- id_prefix
|
||||
- patron
|
||||
|
|
@ -62,3 +63,53 @@
|
|||
x-koha-authorization:
|
||||
permissions:
|
||||
ill: "1"
|
||||
post:
|
||||
x-mojo-to: Illrequests#add
|
||||
operationId: addIllrequest
|
||||
tags:
|
||||
- ill_request
|
||||
summary: Add ILL request
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
description: A JSON object containing informations about the new request
|
||||
required: true
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/ill_request"
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"201":
|
||||
description: Request added
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/ill_request"
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"401":
|
||||
description: Authentication required
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"403":
|
||||
description: Access forbidden
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"409":
|
||||
description: Conflict in creating resource
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"500":
|
||||
description: |
|
||||
Internal server error. Possible `error_code` attribute values:
|
||||
|
||||
* `internal_server_error`
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"503":
|
||||
description: Under maintenance
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
x-koha-authorization:
|
||||
permissions:
|
||||
ill: "1"
|
||||
|
|
|
|||
|
|
@ -64,6 +64,14 @@ definitions:
|
|||
$ref: ./definitions/ill_status.yaml
|
||||
ill_request:
|
||||
$ref: ./definitions/ill_request.yaml
|
||||
illbatch:
|
||||
$ref: ./definitions/illbatch.yaml
|
||||
illbatches:
|
||||
$ref: ./definitions/illbatches.yaml
|
||||
illbatchstatus:
|
||||
$ref: ./definitions/illbatchstatus.yaml
|
||||
illbatchstatuses:
|
||||
$ref: ./definitions/illbatchstatuses.yaml
|
||||
import_batch_profile:
|
||||
$ref: ./definitions/import_batch_profile.yaml
|
||||
import_batch_profiles:
|
||||
|
|
@ -269,6 +277,14 @@ paths:
|
|||
$ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}"
|
||||
/ill/requests:
|
||||
$ref: ./paths/ill_requests.yaml#/~1ill~1requests
|
||||
/illbatches:
|
||||
$ref: ./paths/illbatches.yaml#/~1illbatches
|
||||
"/illbatches/{illbatch_id}":
|
||||
$ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}"
|
||||
/illbatchstatuses:
|
||||
$ref: ./paths/illbatchstatuses.yaml#/~1illbatchstatuses
|
||||
"/illbatchstatuses/{illbatchstatus_code}":
|
||||
$ref: "./paths/illbatchstatuses.yaml#/~1illbatchstatuses~1{illbatchstatus_code}"
|
||||
"/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
|
||||
$ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
|
||||
/import_batch_profiles:
|
||||
|
|
@ -521,6 +537,18 @@ parameters:
|
|||
name: hold_id
|
||||
required: true
|
||||
type: integer
|
||||
illbatch_id_pp:
|
||||
description: Internal ILL batch identifier
|
||||
in: path
|
||||
name: illbatch_id
|
||||
required: true
|
||||
type: integer
|
||||
illbatchstatus_code_pp:
|
||||
description: Internal ILL batch status identifier
|
||||
in: path
|
||||
name: illbatchstatus_code
|
||||
required: true
|
||||
type: string
|
||||
import_batch_profile_id_pp:
|
||||
description: Internal profile identifier
|
||||
in: path
|
||||
|
|
@ -851,6 +879,12 @@ tags:
|
|||
- description: "Manage ILL module backends\n"
|
||||
name: ill_backends
|
||||
x-displayName: ILL backends
|
||||
- description: "Manage ILL module batches\n"
|
||||
name: illbatches
|
||||
x-displayName: ILL batches
|
||||
- description: "Manage ILL module batch statuses\n"
|
||||
name: illbatchstatuses
|
||||
x-displayName: ILL batch statuses
|
||||
- description: "Manage ILL requests\n"
|
||||
name: ill_requests
|
||||
x-displayName: ILL requests
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => "30719",
|
||||
description => "Add ILL batches",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
$dbh->do(q{
|
||||
CREATE TABLE IF NOT EXISTS `illbatches` (
|
||||
`id` int(11) NOT NULL auto_increment, -- Batch ID
|
||||
`name` varchar(100) NOT NULL, -- Unique name of batch
|
||||
`backend` varchar(20) NOT NULL, -- Name of batch backend
|
||||
`borrowernumber` int(11), -- Patron associated with batch
|
||||
`branchcode` varchar(50), -- Branch associated with batch
|
||||
`statuscode` varchar(20), -- Status of batch
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `u_illbatches__name` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
});
|
||||
$dbh->do(q{
|
||||
CREATE TABLE IF NOT EXISTS `illbatch_statuses` (
|
||||
`id` int(11) NOT NULL auto_increment, -- Status ID
|
||||
`name` varchar(100) NOT NULL, -- Name of status
|
||||
`code` varchar(20) NOT NULL, -- Unique, immutable code for status
|
||||
`is_system` int(1), -- Is this status required for system operation
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `u_illbatchstatuses__code` (`code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
});
|
||||
$dbh->do(q{
|
||||
ALTER TABLE `illrequests`
|
||||
ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
|
||||
});
|
||||
$dbh->do(q{
|
||||
ALTER TABLE `illrequests`
|
||||
ADD CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
});
|
||||
$dbh->do(q{
|
||||
ALTER TABLE `illbatches`
|
||||
ADD CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
});
|
||||
$dbh->do(q{
|
||||
ALTER TABLE `illbatches`
|
||||
ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
});
|
||||
$dbh->do(q{
|
||||
ALTER TABLE `illbatches`
|
||||
ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
});
|
||||
|
||||
say $out "Bug 30719: Add ILL batches completed"
|
||||
},
|
||||
};
|
||||
|
|
@ -3301,6 +3301,36 @@ CREATE TABLE `illrequestattributes` (
|
|||
CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
--
|
||||
-- Table structure for table `illbatch_statuses`
|
||||
--
|
||||
DROP TABLE IF EXISTS `illbatch_statuses`;
|
||||
CREATE TABLE `illbatch_statuses` (
|
||||
`id` int(11) NOT NULL auto_increment, -- Status ID
|
||||
`name` varchar(100) NOT NULL, -- Name of status
|
||||
`code` varchar(20) NOT NULL, -- Unique, immutable code for status
|
||||
`is_system` int(1), -- Is this status required for system operation
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `u_illbatchstatuses__code` (`code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Table structure for table `illbatches`
|
||||
--
|
||||
DROP TABLE IF EXISTS `illbatches`;
|
||||
CREATE TABLE `illbatches` (
|
||||
`id` int(11) NOT NULL auto_increment, -- Batch ID
|
||||
`name` varchar(100) NOT NULL, -- Unique name of batch
|
||||
`backend` varchar(20) NOT NULL, -- Name of batch backend
|
||||
`borrowernumber` int(11), -- Patron associated with batch
|
||||
`branchcode` varchar(50), -- Branch associated with batch
|
||||
`statuscode` varchar(20), -- Status of batch
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `u_illbatches__name` (`name`),
|
||||
CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Table structure for table `illrequests`
|
||||
|
|
@ -3330,6 +3360,7 @@ CREATE TABLE `illrequests` (
|
|||
`notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
|
||||
`orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
|
||||
`backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
|
||||
`batch_id` int(11) COMMENT 'Optional ID of batch that this request belongs to',
|
||||
PRIMARY KEY (`illrequest_id`),
|
||||
KEY `illrequests_bnfk` (`borrowernumber`),
|
||||
KEY `illrequests_bcfk_2` (`branchcode`),
|
||||
|
|
@ -3338,7 +3369,8 @@ CREATE TABLE `illrequests` (
|
|||
CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES
|
||||
('New', 'NEW', 1),
|
||||
('In progress', 'IN_PROGRESS', 1),
|
||||
('Completed', 'COMPLETED', 1),
|
||||
('Unknown', 'UNKNOWN', 1);
|
||||
Loading…
Reference in New Issue