Bug 29453

Summary: Add GET endpoints to fetch patron credits and debits
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: REST APIAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: CLOSED FIXED QA Contact: Kyle M Hall (khall) <kyle>
Severity: new feature    
Priority: P5 - low CC: kyle, lucas, lukasz.koszyk, m.de.rooy, michaela.sieber, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20944
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
**Sponsored by** *PTFS Europe*
Version(s) released in:
23.05.00
Circulation function:
Bug Depends on:    
Bug Blocks: 17735, 21043, 28544    
Attachments: Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: (follow-up) Add tests and fix minimum amount in credit.yaml definition
Bug 29453: Add endpoints for fetching patron credits & debits
Bug 29453: (follow-up) Add tests and fix minimum amount in credit.yaml definition

Description Martin Renvoize (ashimema) 2021-11-10 16:08:40 UTC
As the title says.. we should have API routes for fetching a patrons credits and debits by now ;)
Comment 1 Martin Renvoize (ashimema) 2022-02-09 11:43:34 UTC
Created attachment 130350 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.
Comment 2 Martin Renvoize (ashimema) 2022-12-15 15:09:00 UTC
Created attachment 144619 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.
Comment 3 Martin Renvoize (ashimema) 2022-12-15 15:09:22 UTC
Rebased
Comment 4 Lucas Gass (lukeg) 2022-12-16 17:01:21 UTC
When I try testing this, applying patch and restarting all services, then going to 'http://localhost:8081/api/v1/.html' I get this:

The application raised the following error:

  Can't use an undefined value as an ARRAY reference at template mojo/debug.html.ep line 288.
Context:
  283:               </div>
  284:               <div class="tap tap-border-top">tap for more</div>
  285:             </div>
  286:           </div>
  287:           <div class="row">
  288:             % if (@{app->log->history}) {
  289:                 % my $log = join '', map { scalar app->log->format->(@$_) } @{app->log->history};
  290:                 <pre class="mojo-terminal"><code class="nohighlight"><%= $log %></code></pre>
  291:             % }
  292:             % else {
  293:               <div class="alert alert-warning wide" role="alert">
Traceback (most recent call first):

and the StackTrace middleware couldn't catch its stack trace, possibly because your application overrides $SIG{__DIE__} by itself, preventing the middleware from working correctly. Remove the offending code or module that does it: known examples are CGI::Carp and Carp::Always.


Am I doing something wrong?
Comment 5 Martin Renvoize (ashimema) 2022-12-19 09:31:29 UTC
Probably a rebase error on my part.. I'll have a look today.
Comment 6 Martin Renvoize (ashimema) 2022-12-19 14:18:48 UTC
Created attachment 144713 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.
Comment 7 Martin Renvoize (ashimema) 2022-12-19 14:19:21 UTC
Yup, it was a rebase issue.. sorted now :)
Comment 8 Lucas Gass (lukeg) 2022-12-19 16:35:03 UTC
Note: I am testing by playing around with this JS:

let bn = 5;
let api_url = "/api/v1/patrons/" + bn + "/account/debits";
$.getJSON(api_url, function(data) {
    console.log(data)
});


Works well.
Comment 9 Lucas Gass (lukeg) 2022-12-19 16:37:27 UTC
The QA tool complains:

 OK	Koha/Account.pm
 FAIL	Koha/Account/Credit.pm
   FAIL	  valid
		Inconsistent hierarchy during C3 merge of class 'Koha::Account::Credit':
			current merge results [
				Koha::Account::Credit,
			]
			merging failed on 'Koha::Account::Line'

 OK	Koha/Account/Credits.pm
 FAIL	Koha/Account/Debit.pm
   FAIL	  valid
		Inconsistent hierarchy during C3 merge of class 'Koha::Account::Debit':
			current merge results [
				Koha::Account::Debit,
			]
			merging failed on 'Koha::Account::Line'
Comment 10 Lucas Gass (lukeg) 2022-12-19 16:41:27 UTC
Created attachment 144718 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 11 Marcel de Rooy 2023-02-24 08:45:42 UTC
   FAIL   valid
                Inconsistent hierarchy during C3 merge of class 'Koha::Account::Credit':
                        current merge results [
                                Koha::Account::Credit,
                        ]
                        merging failed on 'Koha::Account::Line'

   FAIL   valid
                Inconsistent hierarchy during C3 merge of class 'Koha::Account::Debit':
                        current merge results [
                                Koha::Account::Debit,
                        ]
                        merging failed on 'Koha::Account::Line'
Comment 12 Martin Renvoize (ashimema) 2023-03-01 15:32:21 UTC Comment hidden (obsolete)
Comment 13 Martin Renvoize (ashimema) 2023-03-01 15:35:51 UTC
OK.. the QA Script issue here is a bit of a red herring.. but there is still work to be done anyway.

We ought to have some api tests.. seems I didn't add them here yet!

I'm also considering just outright dropping Koha::Account::Line(s) classes and migrating the appropriate methods into the ::Credit(s) and ::Debit(s) classes instead.. There might still be some need for a base class to share some methods between them.. I'm not sure yet.  Dropping the base class would get rid of the QA Script unhappiness.
Comment 14 Martin Renvoize (ashimema) 2023-03-01 16:14:14 UTC Comment hidden (obsolete)
Comment 15 Martin Renvoize (ashimema) 2023-03-02 15:44:16 UTC
Created attachment 147644 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 16 Agustín Moyano 2023-05-04 14:41:15 UTC
Created attachment 150670 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>
Comment 17 Agustín Moyano 2023-05-04 14:41:18 UTC
Created attachment 150671 [details] [review]
Bug 29453: (follow-up) Add tests and fix minimum amount in credit.yaml definition
Comment 18 Kyle M Hall (khall) 2023-05-05 14:39:03 UTC
Created attachment 150763 [details] [review]
Bug 29453: Add endpoints for fetching patron credits & debits

This patch adds two new API endpoints for fetching a patrons credits and
a patrons debits.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 19 Kyle M Hall (khall) 2023-05-05 14:39:11 UTC
Created attachment 150764 [details] [review]
Bug 29453: (follow-up) Add tests and fix minimum amount in credit.yaml definition

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 20 Tomás Cohen Arazi (tcohen) 2023-05-05 15:14:26 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 21 Martin Renvoize (ashimema) 2023-05-12 15:01:25 UTC
New feature, no backport for 22.11.x series.