Bug 38931: Add endpoints for individual credits and debits

As the title says, we are missing such endpoints and this patch adds
them.

To test:
1. Apply this patches
2. Run:
   $ ktd --shell
  k$ yarn api:bundle
  k$ prove t/db_dependent/api/v1/patrons_accounts.t
=> SUCCESS: The spec builds!
=> SUCCESS: The tests pass!
3. Verify all the codepaths are covered by tests
4. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2025-01-20 16:46:33 -03:00 committed by Lucas Gass
parent 17ad33e2b4
commit 83a823aec5
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
3 changed files with 146 additions and 0 deletions

View File

@ -174,6 +174,30 @@ sub add_credit {
};
}
=head3 get_credit
=cut
sub get_credit {
my $c = shift->openapi->valid_input or return;
my $patron = Koha::Patrons->find( $c->param('patron_id') );
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $credit = $c->objects->find( $patron->account->credits, $c->param('credit_id') );
return $c->render_resource_not_found("Credit")
unless $credit;
return $c->render( status => 200, openapi => $credit );
} catch {
$c->unhandled_exception($_);
};
}
=head3 list_debits
=cut
@ -194,6 +218,30 @@ sub list_debits {
};
}
=head3 get_debit
=cut
sub get_debit {
my $c = shift->openapi->valid_input or return;
my $patron = Koha::Patrons->find( $c->param('patron_id') );
return $c->render_resource_not_found("Patron")
unless $patron;
return try {
my $debit = $c->objects->find( $patron->account->debits, $c->param('debit_id') );
return $c->render_resource_not_found("Debit")
unless $debit;
return $c->render( status => 200, openapi => $debit );
} catch {
$c->unhandled_exception($_);
};
}
=head3 add_debit
=cut

View File

@ -144,6 +144,47 @@
x-koha-authorization:
permissions:
updatecharges: remaining_permissions
"/patrons/{patron_id}/account/credits/{credit_id}":
get:
x-mojo-to: Patrons::Account#get_credit
operationId: getPatronCredit
tags:
- patrons
summary: Get a patron credit
produces:
- application/json
parameters:
- $ref: "../swagger.yaml#/parameters/patron_id_pp"
- $ref: "../swagger.yaml#/parameters/credit_id_pp"
responses:
"200":
description: A patron credit
schema:
$ref: "../swagger.yaml#/definitions/credit"
"400":
description: Bad request
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 error
schema:
$ref: "../swagger.yaml#/definitions/error"
"503":
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
borrowers: edit_borrowers
updatecharges: remaining_permissions
"/patrons/{patron_id}/account/debits":
get:
x-mojo-to: Patrons::Account#list_debits
@ -246,3 +287,44 @@
x-koha-authorization:
permissions:
updatecharges: remaining_permissions
"/patrons/{patron_id}/account/debits/{debit_id}":
get:
x-mojo-to: Patrons::Account#get_debit
operationId: getPatronDebit
tags:
- patrons
summary: Get a patron debit
produces:
- application/json
parameters:
- $ref: "../swagger.yaml#/parameters/patron_id_pp"
- $ref: "../swagger.yaml#/parameters/debit_id_pp"
responses:
"200":
description: A patron debit
schema:
$ref: "../swagger.yaml#/definitions/debit"
"400":
description: Bad request
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 error
schema:
$ref: "../swagger.yaml#/definitions/error"
"503":
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
borrowers: edit_borrowers
updatecharges: remaining_permissions

View File

@ -483,6 +483,10 @@ paths:
$ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account"
"/patrons/{patron_id}/account/credits":
$ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1credits"
"/patrons/{patron_id}/account/credits/{credit_id}":
$ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1credits~1{credit_id}"
"/patrons/{patron_id}/account/debits/{debit_id}":
$ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1debits~1{debit_id}"
"/patrons/{patron_id}/account/debits":
$ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1debits"
"/patrons/{patron_id}/extended_attributes":
@ -719,6 +723,18 @@ parameters:
name: club_id
required: true
type: integer
credit_id_pp:
description: Internal credit identifier
in: path
name: credit_id
required: true
type: integer
debit_id_pp:
description: Internal debit identifier
in: path
name: debit_id
required: true
type: integer
eholdings_title_id_pp:
description: Title internal identifier
in: path