From 595473f194d49bb3c7b8794be3df3e0783fb1a63 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 2 Oct 2024 15:35:27 +0000 Subject: [PATCH] Bug 38204: Add api endpoint to list baskets This patch adds an API endpoint to list baskets It uses CanUserManageBasket to respect the users permissions and sysprefs Test plan: 1) prove t/db_dependent/api/v1/acquisitions_baskets.t Signed-off-by: David Nind --- Koha/REST/V1/Acquisitions/Baskets.pm | 24 +++++++++ api/v1/swagger/definitions/basket.yaml | 27 +++++++--- .../swagger/paths/acquisitions_baskets.yaml | 49 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 2 + 4 files changed, 96 insertions(+), 6 deletions(-) diff --git a/Koha/REST/V1/Acquisitions/Baskets.pm b/Koha/REST/V1/Acquisitions/Baskets.pm index da6152fbb3d..bcd013bb0f5 100644 --- a/Koha/REST/V1/Acquisitions/Baskets.pm +++ b/Koha/REST/V1/Acquisitions/Baskets.pm @@ -59,4 +59,28 @@ sub list_managers { }; } +=head3 list + +Return a list of baskets + +=cut + +sub list { + my $c = shift->openapi->valid_input or return; + + return try { + + my $baskets_rs = Koha::Acquisition::Baskets->new; + my $baskets = $c->objects->search( $baskets_rs ); + + return $c->render( + status => 200, + openapi => $baskets + ); + } + catch { + $c->unhandled_exception($_); + }; +} + 1; diff --git a/api/v1/swagger/definitions/basket.yaml b/api/v1/swagger/definitions/basket.yaml index 8ab8ff1d69e..35d795bd602 100644 --- a/api/v1/swagger/definitions/basket.yaml +++ b/api/v1/swagger/definitions/basket.yaml @@ -5,7 +5,9 @@ properties: type: integer description: Internal identifier for the basket name: - type: string + type: + - string + - "null" description: Basket name internal_note: type: @@ -18,7 +20,9 @@ properties: - "null" description: Vendor note contract_id: - type: integer + type: + - integer + - "null" description: Internal identifier of the linked contract creation_date: type: @@ -35,7 +39,7 @@ properties: vendor_id: type: integer description: Internal identifier for the vendor - authorised_by: + creator_id: type: - integer - "null" @@ -45,12 +49,12 @@ properties: - integer - "null" description: links this basket to its group (aqbasketgroups.id) - delivery_library: + delivery_library_id: type: - string - "null" description: basket delivery place - billing_library: + billing_library_id: type: - string - "null" @@ -63,12 +67,23 @@ properties: standing: type: boolean description: If the orders in this basket are standing + closed: + type: boolean + description: Is the basket closed + note: + type: + - string + - "null" + description: basket notes create_items: - type: string + type: + - string + - "null" enum: - ordering - receiving - cataloguing + - null description: "When items should be created for orders in this basket (Options: 'ordering', 'receiving', 'cataloguing'. Null means system wide config)" additionalProperties: false diff --git a/api/v1/swagger/paths/acquisitions_baskets.yaml b/api/v1/swagger/paths/acquisitions_baskets.yaml index f3e8a0d2cb3..010b53af949 100644 --- a/api/v1/swagger/paths/acquisitions_baskets.yaml +++ b/api/v1/swagger/paths/acquisitions_baskets.yaml @@ -1,4 +1,53 @@ --- +/acquisitions/baskets: + get: + x-mojo-to: Acquisitions::Baskets#list + operationId: listBaskets + description: This resource returns a list of baskets + summary: List of baskets + tags: + - baskets + parameters: + - $ref: "../swagger.yaml#/parameters/match" + - $ref: "../swagger.yaml#/parameters/order_by" + - $ref: "../swagger.yaml#/parameters/page" + - $ref: "../swagger.yaml#/parameters/per_page" + - $ref: "../swagger.yaml#/parameters/q_param" + - $ref: "../swagger.yaml#/parameters/q_body" + produces: + - application/json + responses: + "200": + description: A list of baskets + schema: + type: array + items: + $ref: "../swagger.yaml#/definitions/basket" + "400": + description: | + Bad request. Possible `error_code` attribute values: + + * `invalid_query` + 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: + acquisition: order_manage /acquisitions/baskets/managers: get: x-mojo-to: Acquisitions::Baskets#list_managers diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index e6292df58bb..d26e7d4fad5 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -185,6 +185,8 @@ definitions: vendor_issue: $ref: ./definitions/vendor_issue.yaml paths: + /acquisitions/baskets: + $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets /acquisitions/baskets/managers: $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers /acquisitions/edifiles: -- 2.47.0