=head2 Methods
-=head3 list_vendors
+=head3 list
Controller function that handles listing Koha::Acquisition::Bookseller objects
=cut
-sub list_vendors {
+sub list {
my $c = shift->openapi->valid_input or return;
- my $args = _to_model($c->req->params->to_hash);
- my $filter;
-
- for my $filter_param ( keys %$args ) {
- $filter->{$filter_param} = { LIKE => $args->{$filter_param} . "%" }
- if $args->{$filter_param};
- }
-
return try {
- my $vendors = Koha::Acquisition::Booksellers->search($filter);
+ my $vendors_rs = Koha::Acquisition::Booksellers->new;
+ my $vendors = $c->objects->search( $vendors_rs );
return $c->render(
status => 200,
- openapi => $vendors->to_api
+ openapi => $vendors
);
}
catch {
};
}
-=head3 get_vendor
+=head3 get
Controller function that handles retrieving a single Koha::Acquisition::Bookseller
=cut
-sub get_vendor {
+sub get {
my $c = shift->openapi->valid_input or return;
my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
);
}
-=head3 add_vendor
+=head3 add
Controller function that handles adding a new Koha::Acquisition::Bookseller object
=cut
-sub add_vendor {
+sub add {
my $c = shift->openapi->valid_input or return;
- my $vendor = Koha::Acquisition::Bookseller->new( _to_model( $c->validation->param('body') ) );
+ my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->validation->param('body') );
return try {
$vendor->store;
};
}
-=head3 update_vendor
+=head3 update
Controller function that handles updating a Koha::Acquisition::Bookseller object
=cut
-sub update_vendor {
+sub update {
my $c = shift->openapi->valid_input or return;
my $vendor;
return try {
$vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
- $vendor->set( _to_model( $c->validation->param('body') ) );
+ $vendor->set_from_api( $c->validation->param('body') );
$vendor->store();
return $c->render(
status => 200,
}
-=head3 delete_vendor
+=head3 delete
Controller function that handles deleting a Koha::Acquisition::Bookseller object
=cut
-sub delete_vendor {
+sub delete {
my $c = shift->openapi->valid_input or return;
my $vendor;
}
-=head3 _to_api
-
-Helper function that maps a Koha::Acquisition::Bookseller object into
-the attribute names the exposed REST api spec.
-
-=cut
-
-sub _to_api {
- my $vendor = shift;
-
- # Delete unused fields
- delete $vendor->{booksellerfax};
- delete $vendor->{bookselleremail};
- delete $vendor->{booksellerurl};
- delete $vendor->{currency};
- delete $vendor->{othersupplier};
-
- # Rename changed fields
- $vendor->{list_currency} = delete $vendor->{listprice};
- $vendor->{invoice_currency} = delete $vendor->{invoiceprice};
- $vendor->{gst} = delete $vendor->{gstreg};
- $vendor->{list_includes_gst} = delete $vendor->{listincgst};
- $vendor->{invoice_includes_gst} = delete $vendor->{invoiceincgst};
-
- return $vendor;
-}
-
-=head3 _to_model
-
-Helper function that maps REST api objects into Koha::Acquisition::Bookseller
-attribute names.
-
-=cut
-
-sub _to_model {
- my $vendor = shift;
-
- # Rename back
- $vendor->{listprice} = delete $vendor->{list_currency};
- $vendor->{invoiceprice} = delete $vendor->{invoice_currency};
- $vendor->{gstreg} = delete $vendor->{gst};
- $vendor->{listincgst} = delete $vendor->{list_includes_gst};
- $vendor->{invoiceincgst} = delete $vendor->{invoice_includes_gst};
-
- return $vendor;
-}
-
1;
{
"/acquisitions/vendors": {
"get": {
- "x-mojo-to": "Acquisitions::Vendors#list_vendors",
+ "x-mojo-to": "Acquisitions::Vendors#list",
"operationId": "listVendors",
"tags": ["acquisitions","vendors"],
"produces": [
"description": "Case insensitive search on vendor's account number",
"required": false,
"type": "string"
+ }, {
+ "$ref": "../parameters.json#/match"
+ }, {
+ "$ref": "../parameters.json#/order_by"
+ }, {
+ "$ref": "../parameters.json#/page"
+ }, {
+ "$ref": "../parameters.json#/per_page"
}],
"responses": {
"200": {
}
},
"post": {
- "x-mojo-to": "Acquisitions::Vendors#add_vendor",
+ "x-mojo-to": "Acquisitions::Vendors#add",
"operationId": "addVendor",
"tags": ["acquisitions","vendors"],
"parameters": [{
},
"/acquisitions/vendors/{vendor_id}": {
"get": {
- "x-mojo-to": "Acquisitions::Vendors#get_vendor",
+ "x-mojo-to": "Acquisitions::Vendors#get",
"operationId": "getVendor",
"tags": ["acquisitions","vendors"],
"parameters": [{
}
},
"put": {
- "x-mojo-to": "Acquisitions::Vendors#update_vendor",
+ "x-mojo-to": "Acquisitions::Vendors#update",
"operationId": "updateVendor",
"tags": ["acquisitions","vendors"],
"parameters": [{
}
},
"delete": {
- "x-mojo-to": "Acquisitions::Vendors#delete_vendor",
+ "x-mojo-to": "Acquisitions::Vendors#delete",
"operationId": "deleteVendor",
"tags": ["acquisitions","vendors"],
"parameters": [{