From 889a834b4c34239ad041a517914ee10c586c4be1 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 21 Jan 2026 09:39:56 +0000 Subject: [PATCH] Bug 26355: Update API specs for categories Signed-off-by: Hannah Dunne-Howrie Adds the new db columns to the category specs and adds a POST endpoint for patron categories. Also adds a check for self renewal eligibility to the patron definition --- Koha/REST/V1/Patrons/Categories.pm | 20 ++++++++ api/v1/swagger/definitions/patron.yaml | 4 ++ .../swagger/definitions/patron_category.yaml | 22 +++++++++ api/v1/swagger/paths/patron_categories.yaml | 46 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 ++ 5 files changed, 96 insertions(+) diff --git a/Koha/REST/V1/Patrons/Categories.pm b/Koha/REST/V1/Patrons/Categories.pm index 6fa4ec84c94..f2439ff1b05 100644 --- a/Koha/REST/V1/Patrons/Categories.pm +++ b/Koha/REST/V1/Patrons/Categories.pm @@ -50,4 +50,24 @@ sub list { }; } +=head3 add + +=cut + +sub add { + my $c = shift->openapi->valid_input or return; + + return try { + my $category = Koha::Patron::Category->new_from_api( $c->req->json ); + $category->store; + $c->res->headers->location( $c->req->url->to_string . '/' . $category->categorycode ); + return $c->render( + status => 201, + openapi => $c->objects->to_api($category), + ); + } catch { + $c->unhandled_exception($_); + }; +} + 1; diff --git a/api/v1/swagger/definitions/patron.yaml b/api/v1/swagger/definitions/patron.yaml index afb252e1f17..8fa5e1034e7 100644 --- a/api/v1/swagger/definitions/patron.yaml +++ b/api/v1/swagger/definitions/patron.yaml @@ -408,6 +408,10 @@ properties: - "null" description: patron's primary contact method maxLength: 45 + self_renewal_available: + type: + - boolean + description: set to 1 if the patron is eligible to self renew and is within the renewal criteria _strings: type: - object diff --git a/api/v1/swagger/definitions/patron_category.yaml b/api/v1/swagger/definitions/patron_category.yaml index da548a6980d..c5516f37947 100644 --- a/api/v1/swagger/definitions/patron_category.yaml +++ b/api/v1/swagger/definitions/patron_category.yaml @@ -129,6 +129,28 @@ properties: type: - boolean description: Set threshold of debt allowed before issues are blocked + self_renewal_enabled: + type: + - boolean + description: Determine whether self-renewal is allowed for this category + self_renewal_availability_start: + type: + - number + - "null" + description: How many days in advance of expiry self-renewal should become available + self_renewal_if_expired: + type: + - number + - "null" + description: How many days after expiry self-renewal should still be available + self_renewal_fines_block: + type: + - number + - "null" + description: How much can be accrued in fines before self-renewal is blocked + self_renewal_failure_message: + type: string + description: The error message to display if self-renewal fails additionalProperties: false required: - patron_category_id diff --git a/api/v1/swagger/paths/patron_categories.yaml b/api/v1/swagger/paths/patron_categories.yaml index 98d261e0705..0a3836516ba 100644 --- a/api/v1/swagger/paths/patron_categories.yaml +++ b/api/v1/swagger/paths/patron_categories.yaml @@ -52,3 +52,49 @@ x-koha-authorization: permissions: parameters: manage_patron_categories + post: + x-mojo-to: Patrons::Categories#add + operationId: addCategory + tags: + - categories + summary: Add category + parameters: + - name: body + in: body + description: A JSON object containing informations about the new hold + required: true + schema: + $ref: "../swagger.yaml#/definitions/patron_category" + produces: + - application/json + responses: + "201": + description: Category added + schema: + $ref: "../swagger.yaml#/definitions/patron_category" + "400": + description: Bad request + schema: + $ref: "../swagger.yaml#/definitions/error" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + 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: + parameters: manage_patron_categories diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 9a9b7af7565..1df3ad5a837 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -154,6 +154,8 @@ definitions: $ref: ./definitions/patron_balance.yaml patron_category: $ref: ./definitions/patron_category.yaml + patron_self_renewal: + $ref: ./definitions/patron_self_renewal.yaml patron_extended_attribute: $ref: ./definitions/patron_extended_attribute.yaml preservation_config: @@ -581,6 +583,8 @@ paths: $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1ill~1requests" "/public/patrons/{patron_id}/password": $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1password" + "/public/patrons/self_renewal": + $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1self_renewal" "/public/tickets": $ref: "./paths/tickets.yaml#/~1public~1tickets" /quotes: -- 2.39.5