Bugzilla – Attachment 144623 Details for
Bug 21043
Add POST endpoint for patron debits
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21043: Untested code
Bug-21043-Untested-code.patch (text/plain), 3.48 KB, created by
Martin Renvoize (ashimema)
on 2022-12-15 15:55:48 UTC
(
hide
)
Description:
Bug 21043: Untested code
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-12-15 15:55:48 UTC
Size:
3.48 KB
patch
obsolete
>From e6b9cdf25082f7cb612f26bc831b139e7e5facf6 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 15 Dec 2022 15:50:55 +0000 >Subject: [PATCH] Bug 21043: Untested code > >This patch adds a rough idea of how we might go about adding such an api >point. >--- > Koha/REST/V1/Patrons/Account.pm | 34 ++++++++++++++++ > api/v1/swagger/paths/patrons_account.yaml | 47 +++++++++++++++++++++++ > 2 files changed, 81 insertions(+) > >diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm >index 2238ffc0757..bed62e2b1fb 100644 >--- a/Koha/REST/V1/Patrons/Account.pm >+++ b/Koha/REST/V1/Patrons/Account.pm >@@ -205,4 +205,38 @@ sub list_debits { > }; > } > >+=head3 add_debit >+ >+=cut >+ >+sub add_debit { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $patron_id = $c->validation->param('patron_id'); >+ my $patron = Koha::Patrons->find($patron_id); >+ >+ unless ($patron) { >+ return $c->render( status => 404, openapi => { error => "Patron not found." } ); >+ } >+ >+ return try { >+ my $data = Koha::Patron::Account::Debit->new_from_api( >+ $c->validation->param('body') )->unblessed; >+ >+ $data->{interface} = 'api'; # Should this always be API, or should we allow the API consumer to choose? >+ $data->{user_id} = $patron->borrowernumber; # Should this be API user OR staff the API may be acting on behalf of? >+ >+ my $debit = $patron->account->add_debit($data); >+ >+ $c->res->headers->location( $c->req->url->to_string . '/' . $debit->id ); >+ return $c->render( >+ status => 201, >+ openapi => $debit->to_api >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths/patrons_account.yaml b/api/v1/swagger/paths/patrons_account.yaml >index e9620ae868d..98c00a6c70e 100644 >--- a/api/v1/swagger/paths/patrons_account.yaml >+++ b/api/v1/swagger/paths/patrons_account.yaml >@@ -177,3 +177,50 @@ > permissions: > borrowers: edit_borrowers > updatecharges: remaining_permissions >+ post: >+ x-mojo-to: Patrons::Account#add_debit >+ operationId: addPatronDebit >+ tags: >+ - patrons >+ summary: Add debit to a patron's account >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/patron_id_pp" >+ - name: body >+ in: body >+ description: A JSON object containing debit information >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/patron_account_debit" >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Debit added >+ schema: >+ $ref: "../swagger.yaml#/definitions/account_line" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Patron not found >+ 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: >+ updatecharges: remaining_permissions >-- >2.39.0
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 21043
:
144615
|
144623
|
147457
|
147458
|
147459
|
147498
|
147566
|
147567
|
147568
|
147642
|
147643
|
150765
|
150766