Bugzilla – Attachment 56695 Details for
Bug 15165
REST API routes to list, edit and pay borrower's accountlines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15165 - Add API route to edit accountlines
Bug-15165---Add-API-route-to-edit-accountlines.patch (text/plain), 7.34 KB, created by
Lari Taskula
on 2016-10-20 13:19:56 UTC
(
hide
)
Description:
Bug 15165 - Add API route to edit accountlines
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2016-10-20 13:19:56 UTC
Size:
7.34 KB
patch
obsolete
>From 52a50003542c8fe8fd3e2c24bbae7bf8b56a27d9 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Tue, 10 Nov 2015 16:43:35 +0100 >Subject: [PATCH] Bug 15165 - Add API route to edit accountlines > >PUT /accountlines/{accountlines_id} (edit) > >Test plan: >1. Open a browser tab on Koha staff and log in (to create CGISESSID > cookie). You should have permission updatecharges. >2. Send PUT request to http://yourlibrary/api/v1/accountlines/YYY > where YYY is one of your accountlines_id. See the body definition > in definitions/editAccountlineBody.json and use this in your PUT request. >3. Run unit tests in t/db_dependent/api/v1/accountlines.t >--- > Koha/REST/V1/Accountline.pm | 17 ++++++++ > api/v1/swagger/parameters.json | 3 ++ > api/v1/swagger/parameters/accountline.json | 9 +++++ > api/v1/swagger/paths.json | 3 ++ > api/v1/swagger/paths/accountlines.json | 62 ++++++++++++++++++++++++++++++ > t/db_dependent/api/v1/accountlines.t | 46 +++++++++++++++++++++- > 6 files changed, 139 insertions(+), 1 deletion(-) > create mode 100644 api/v1/swagger/parameters/accountline.json > >diff --git a/Koha/REST/V1/Accountline.pm b/Koha/REST/V1/Accountline.pm >index 4acf294..23c2491 100644 >--- a/Koha/REST/V1/Accountline.pm >+++ b/Koha/REST/V1/Accountline.pm >@@ -31,4 +31,21 @@ sub list { > return $c->$cb($accountlines->unblessed, 200); > } > >+ >+sub edit { >+ my ($c, $args, $cb) = @_; >+ >+ my $accountline = Koha::Account::Lines->find($args->{accountlines_id}); >+ unless ($accountline) { >+ return $c->$cb({error => "Accountline not found"}, 404); >+ } >+ >+ my $body = $c->req->json; >+ >+ $accountline->set( $body ); >+ $accountline->store(); >+ >+ return $c->$cb($accountline->unblessed(), 200); >+} >+ > 1; >diff --git a/api/v1/swagger/parameters.json b/api/v1/swagger/parameters.json >index b20e19f..6be33c3 100644 >--- a/api/v1/swagger/parameters.json >+++ b/api/v1/swagger/parameters.json >@@ -1,4 +1,7 @@ > { >+ "accountlinesIdPathParam": { >+ "$ref": "parameters/accountline.json#/accountlinesIdPathParam" >+ }, > "borrowernumberPathParam": { > "$ref": "parameters/patron.json#/borrowernumberPathParam" > }, >diff --git a/api/v1/swagger/parameters/accountline.json b/api/v1/swagger/parameters/accountline.json >new file mode 100644 >index 0000000..d1fb361 >--- /dev/null >+++ b/api/v1/swagger/parameters/accountline.json >@@ -0,0 +1,9 @@ >+{ >+ "accountlinesIdPathParam": { >+ "name": "accountlines_id", >+ "in": "path", >+ "description": "Internal accountline identifier", >+ "required": true, >+ "type": "integer" >+ } >+} >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index 3e3f8c1..e00dffc 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -2,6 +2,9 @@ > "/accountlines": { > "$ref": "paths/accountlines.json#/~1accountlines" > }, >+ "/accountlines/{accountlines_id}": { >+ "$ref": "paths/accountlines.json#/~1accountlines~1{accountlines_id}" >+ }, > "/holds": { > "$ref": "paths/holds.json#/~1holds" > }, >diff --git a/api/v1/swagger/paths/accountlines.json b/api/v1/swagger/paths/accountlines.json >index d7aff5c..d89056d 100644 >--- a/api/v1/swagger/paths/accountlines.json >+++ b/api/v1/swagger/paths/accountlines.json >@@ -31,5 +31,67 @@ > } > } > } >+ }, >+ "/accountlines/{accountlines_id}": { >+ "put": { >+ "operationId": "editAccountlines", >+ "tags": ["accountlines"], >+ "produces": [ >+ "application/json" >+ ], >+ "parameters": [ >+ { "$ref": "../parameters.json#/accountlinesIdPathParam" }, >+ { >+ "name": "body", >+ "in": "body", >+ "description": "A JSON object containing fields to modify", >+ "required": true, >+ "schema": { >+ "type": "object", >+ "properties": { >+ "amount": { >+ "description": "Amount" >+ }, >+ "amountoutstanding": { >+ "description": "Amount outstanding" >+ }, >+ "note": { >+ "description": "Accountline note" >+ }, >+ "meansofpayment": { >+ "description": "Means of payment" >+ } >+ } >+ } >+ } >+ ], >+ "consumes": ["application/json"], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "Updated accountline", >+ "schema": { "$ref": "../definitions.json#/accountline" } >+ }, >+ "400": { >+ "description": "Missing or wrong parameters", >+ "schema": { "$ref": "../definitions.json#/error" } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "404": { >+ "description": "Accountline not found", >+ "schema": { "$ref": "../definitions.json#/error" } >+ } >+ }, >+ "x-koha-authorization": { >+ "permissions": { >+ "updatecharges": "1" >+ } >+ } >+ } > } > } >diff --git a/t/db_dependent/api/v1/accountlines.t b/t/db_dependent/api/v1/accountlines.t >index ceafef0..d395603 100644 >--- a/t/db_dependent/api/v1/accountlines.t >+++ b/t/db_dependent/api/v1/accountlines.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 22; > use Test::Mojo; > use t::lib::TestBuilder; > >@@ -25,6 +25,7 @@ use C4::Auth; > use C4::Context; > > use Koha::Database; >+use Koha::Account::Line; > > my $builder = t::lib::TestBuilder->new(); > >@@ -41,6 +42,9 @@ my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; > $t->get_ok('/api/v1/accountlines') > ->status_is(401); > >+$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) >+ ->status_is(401); >+ > my $loggedinuser = $builder->build({ > source => 'Borrower', > value => { >@@ -115,4 +119,44 @@ $json = $t->tx->res->json; > ok(ref $json eq 'ARRAY', 'response is a JSON array'); > ok(scalar @$json == 4, 'response array contains 3 elements'); > >+# Editing accountlines tests >+my $put_data = { >+ 'amount' => -19, >+ 'amountoutstanding' => -19 >+}; >+ >+$tx = $t->ua->build_tx( >+ PUT => "/api/v1/accountlines/11224409" >+ => {Accept => '*/*'} >+ => json => $put_data); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(404); >+ >+my $accountline_to_edit = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0]; >+ >+$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" => json => $put_data); >+$tx->req->cookies({name => 'CGISESSID', value => $borrowersession->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(403); >+ >+$tx = $t->ua->build_tx( >+ PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" >+ => {Accept => '*/*'} >+ => json => $put_data); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(200); >+ >+my $accountline_edited = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0]; >+ >+is($accountline_edited->{amount}, '-19.000000'); >+is($accountline_edited->{amountoutstanding}, '-19.000000'); >+ >+ >+# Payment tests >+ > $dbh->rollback; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15165
:
44804
|
44805
|
44806
|
45259
|
50189
|
50190
|
50191
|
50790
|
52681
|
52682
|
52683
|
55033
|
55034
|
55035
|
56694
|
56695
|
56696
|
57843
|
57844
|
57845
|
57846
|
59239
|
59240
|
59241
|
59242
|
59932
|
59933
|
59934
|
60180
|
62769
|
62770
|
62771
|
62772
|
62773
|
62774
|
62775