Bugzilla – Attachment 44804 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 list accountlines
Bug-15165---Add-API-route-to-list-accountlines.patch (text/plain), 11.05 KB, created by
Alex Arnaud
on 2015-11-12 13:49:34 UTC
(
hide
)
Description:
Bug 15165 - Add API route to list accountlines
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2015-11-12 13:49:34 UTC
Size:
11.05 KB
patch
obsolete
>From dac524b33cb1d037844883e2112424f9a5b8a4d4 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Tue, 10 Nov 2015 09:52:45 +0100 >Subject: [PATCH] Bug 15165 - Add API route to list accountlines > >--- > Koha/Accountline.pm | 30 ++++++++++ > Koha/Accountlines.pm | 35 ++++++++++++ > Koha/REST/V1/Accountline.pm | 39 +++++++++++++ > api/v1/definitions/accountline.json | 56 ++++++++++++++++++ > api/v1/definitions/index.json | 1 + > api/v1/swagger.json | 26 +++++++++ > t/db_dependent/api/v1/accountlines.t | 104 ++++++++++++++++++++++++++++++++++ > 7 files changed, 291 insertions(+) > create mode 100644 Koha/Accountline.pm > create mode 100644 Koha/Accountlines.pm > create mode 100644 Koha/REST/V1/Accountline.pm > create mode 100644 api/v1/definitions/accountline.json > create mode 100644 t/db_dependent/api/v1/accountlines.t > >diff --git a/Koha/Accountline.pm b/Koha/Accountline.pm >new file mode 100644 >index 0000000..be48049 >--- /dev/null >+++ b/Koha/Accountline.pm >@@ -0,0 +1,30 @@ >+package Koha::Accountline; >+ >+# Copyright 2015 BibLibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+sub type { >+ return 'Accountline'; >+} >+ >+1; >diff --git a/Koha/Accountlines.pm b/Koha/Accountlines.pm >new file mode 100644 >index 0000000..88214e1 >--- /dev/null >+++ b/Koha/Accountlines.pm >@@ -0,0 +1,35 @@ >+package Koha::Accountlines; >+ >+# Copyright 2015 BibLibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+use Koha::Accountline; >+ >+use base qw(Koha::Objects); >+ >+sub type { >+ return 'Accountline'; >+} >+ >+sub object_class { >+ return 'Koha::Accountline'; >+} >+ >+1; >diff --git a/Koha/REST/V1/Accountline.pm b/Koha/REST/V1/Accountline.pm >new file mode 100644 >index 0000000..04a92de >--- /dev/null >+++ b/Koha/REST/V1/Accountline.pm >@@ -0,0 +1,39 @@ >+package Koha::REST::V1::Accountline; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use C4::Auth qw( haspermission ); >+use Koha::Accountlines; >+ >+sub list { >+ my ($c, $args, $cb) = @_; >+ >+ my $user = $c->stash('koha.user'); >+ unless ($user && haspermission($user->userid, {updatecharges => 1})) { >+ return $c->$cb({error => "You don't have the required permission"}, 403); >+ } >+ >+ my $params = $c->req->params->to_hash; >+ my $accountlines = Koha::Accountlines->search($params); >+ >+ return $c->$cb($accountlines->unblessed, 200); >+} >+ >+1; >diff --git a/api/v1/definitions/accountline.json b/api/v1/definitions/accountline.json >new file mode 100644 >index 0000000..d4b612e >--- /dev/null >+++ b/api/v1/definitions/accountline.json >@@ -0,0 +1,56 @@ >+{ >+ "type": "object", >+ "properties": { >+ "accountlines_id": { >+ "description": "Internal account line identifier" >+ }, >+ "borrowernumber": { >+ "description": "Internal borrower identifier" >+ }, >+ "accountno": { >+ "description": "?" >+ }, >+ "itemnumber": { >+ "description": "Internal item identifier" >+ }, >+ "date": { >+ "description": "Date when the account line was created" >+ }, >+ "time": { >+ "description": "Time when the account line was created" >+ }, >+ "amount": { >+ "description": "Amount" >+ }, >+ "description": { >+ "description": "Description of account line" >+ }, >+ "accounttype": { >+ "description": "Type of accountline" >+ }, >+ "amountoutstanding": { >+ "description": "Amount outstanding" >+ }, >+ "lastincrement": { >+ "description": "?" >+ }, >+ "timestamp": { >+ "description": "When the account line was last updated" >+ }, >+ "notify_id": { >+ "description": "?" >+ }, >+ "notify_level": { >+ "description": "?" >+ }, >+ "note": { >+ "description": "Accountline note" >+ }, >+ "manager_id": { >+ "description": "Borrowernumber of user that created the account line" >+ }, >+ "meansofpayment": { >+ "description": "Means of payment" >+ } >+ } >+} >diff --git a/api/v1/definitions/index.json b/api/v1/definitions/index.json >index e940eee..e05f0c2 100644 >--- a/api/v1/definitions/index.json >+++ b/api/v1/definitions/index.json >@@ -1,4 +1,5 @@ > { > "patron": { "$ref": "patron.json" }, >+ "accountline": { "$ref": "accountline.json" }, > "error": { "$ref": "error.json" } > } >diff --git a/api/v1/swagger.json b/api/v1/swagger.json >index e821c44..37e4baa 100644 >--- a/api/v1/swagger.json >+++ b/api/v1/swagger.json >@@ -73,6 +73,32 @@ > } > } > } >+ }, >+ "/accountlines": { >+ "get": { >+ "operationId": "listAccountlines", >+ "tags": ["accountlines"], >+ "produces": [ >+ "application/json" >+ ], >+ "responses": { >+ "200": { >+ "description": "A list of accountlines", >+ "schema": { >+ "type": "array", >+ "items": { >+ "$ref": "#/definitions/accountline" >+ } >+ } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { >+ "$ref": "#/definitions/error" >+ } >+ } >+ } >+ } > } > }, > "definitions": { >diff --git a/t/db_dependent/api/v1/accountlines.t b/t/db_dependent/api/v1/accountlines.t >new file mode 100644 >index 0000000..cbe98c8 >--- /dev/null >+++ b/t/db_dependent/api/v1/accountlines.t >@@ -0,0 +1,104 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Test::More tests => 10; >+use Test::Mojo; >+use t::lib::TestBuilder; >+ >+use C4::Auth; >+use C4::Context; >+ >+use Koha::Database; >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+$ENV{REMOTE_ADDR} = '127.0.0.1'; >+my $t = Test::Mojo->new('Koha::REST::V1'); >+ >+my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; >+my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; >+ >+$t->get_ok('/api/v1/accountlines') >+ ->status_is(403); >+ >+my $loggedinuser = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ flags => 1024 >+ } >+}); >+ >+my $borrower = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ } >+}); >+ >+my $borrower2 = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ } >+}); >+my $borrowernumber = $borrower->{borrowernumber}; >+my $borrowernumber2 = $borrower2->{borrowernumber}; >+ >+$dbh->do(q| DELETE FROM accountlines |); >+$dbh->do(q| >+ INSERT INTO accountlines (borrowernumber, amount, accounttype) >+ VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F'), (?, 10, 'F') >+ |, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2); >+ >+my $session = C4::Auth::get_session(''); >+$session->param('number', $loggedinuser->{ borrowernumber }); >+$session->param('id', $loggedinuser->{ userid }); >+$session->param('ip', '127.0.0.1'); >+$session->param('lasttime', time()); >+$session->flush; >+ >+my $tx = $t->ua->build_tx(GET => "/api/v1/accountlines?borrowernumber=$borrowernumber"); >+$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 $json = $t->tx->res->json; >+ok(ref $json eq 'ARRAY', 'response is a JSON array'); >+ok(scalar @$json == 3, 'response array contains 3 elements'); >+ >+$tx = $t->ua->build_tx(GET => "/api/v1/accountlines"); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(200); >+ >+$json = $t->tx->res->json; >+ok(ref $json eq 'ARRAY', 'response is a JSON array'); >+ok(scalar @$json == 4, 'response array contains 3 elements'); >+ >+$dbh->rollback; >-- >1.7.10.4
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