Bugzilla – Attachment 159420 Details for
Bug 35430
Add endpoints for managing stock rotation rota's
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35430: Add rota endpoints for stockrotation
Bug-35430-Add-rota-endpoints-for-stockrotation.patch (text/plain), 12.42 KB, created by
David Nind
on 2023-11-30 18:54:05 UTC
(
hide
)
Description:
Bug 35430: Add rota endpoints for stockrotation
Filename:
MIME Type:
Creator:
David Nind
Created:
2023-11-30 18:54:05 UTC
Size:
12.42 KB
patch
obsolete
>From 769367f86a641864a3a01756bfeb4ffc77fc33f3 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 29 Nov 2023 13:50:59 +0000 >Subject: [PATCH] Bug 35430: Add rota endpoints for stockrotation > >This patch adds the CRUD endpoints for stock rotation rota's. > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/REST/V1/StockRotation/Rotas.pm | 139 +++++++++++++++++++ > api/v1/swagger/definitions/rota.yaml | 27 ++++ > api/v1/swagger/paths/rotas.yaml | 200 ++++++++++++++++++++++++++- > api/v1/swagger/swagger.yaml | 16 ++- > 4 files changed, 379 insertions(+), 3 deletions(-) > create mode 100644 Koha/REST/V1/StockRotation/Rotas.pm > create mode 100644 api/v1/swagger/definitions/rota.yaml > >diff --git a/Koha/REST/V1/StockRotation/Rotas.pm b/Koha/REST/V1/StockRotation/Rotas.pm >new file mode 100644 >index 0000000000..7abe4dbef2 >--- /dev/null >+++ b/Koha/REST/V1/StockRotation/Rotas.pm >@@ -0,0 +1,139 @@ >+package Koha::REST::V1::StockRotation::Rotas; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::StockRotationRotas; >+ >+use Try::Tiny qw( catch try ); >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 list >+ >+=cut >+ >+sub list { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $rotas = $c->objects->search( Koha::StockRotationRotas->new ); >+ return $c->render( status => 200, openapi => $rotas ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+ >+} >+ >+=head3 get >+ >+=cut >+ >+sub get { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') ); >+ unless ($rota) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Rota not found" } >+ ); >+ } >+ >+ return $c->render( status => 200, openapi => $rota->to_api ); >+ } catch { >+ $c->unhandled_exception($_); >+ } >+} >+ >+=head3 add >+ >+=cut >+ >+sub add { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $rota = Koha::StockRotationRota->new_from_api( $c->req->json ); >+ $rota->store; >+ $c->res->headers->location( $c->req->url->to_string . '/' . $rota->rota_id ); >+ return $c->render( >+ status => 201, >+ openapi => $rota->to_api >+ ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 update >+ >+=cut >+ >+sub update { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') ); >+ >+ if ( not defined $rota ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ >+ return try { >+ $rota->set_from_api( $c->req->json ); >+ $rota->store(); >+ return $c->render( status => 200, openapi => $rota->to_api ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 delete >+ >+=cut >+ >+sub delete { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $rota = Koha::StockRotationRotas->find( $c->param('rota_id') ); >+ if ( not defined $rota ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ >+ return try { >+ $rota->delete; >+ return $c->render( >+ status => 204, >+ openapi => q{} >+ ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+1; >diff --git a/api/v1/swagger/definitions/rota.yaml b/api/v1/swagger/definitions/rota.yaml >new file mode 100644 >index 0000000000..581e007b5e >--- /dev/null >+++ b/api/v1/swagger/definitions/rota.yaml >@@ -0,0 +1,27 @@ >+--- >+type: object >+properties: >+ rota_id: >+ type: integer >+ description: internally assigned rota identifier >+ readOnly: true >+ title: >+ description: rota title >+ type: string >+ description: >+ description: rota description >+ type: >+ - string >+ - "null" >+ cyclical: >+ description: rota is cyclical >+ type: boolean >+ active: >+ description: rota is active >+ type: boolean >+additionalProperties: false >+required: >+ - title >+ - description >+ - cyclical >+ - active >diff --git a/api/v1/swagger/paths/rotas.yaml b/api/v1/swagger/paths/rotas.yaml >index dd36750049..69c079afc7 100644 >--- a/api/v1/swagger/paths/rotas.yaml >+++ b/api/v1/swagger/paths/rotas.yaml >@@ -1,11 +1,209 @@ > --- >+"/rotas": >+ get: >+ x-mojo-to: StockRotation::Rotas#list >+ operationId: listRotas >+ tags: >+ - stockrotation >+ summary: List rotas >+ produces: >+ - application/json >+ 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" >+ - $ref: "../swagger.yaml#/parameters/request_id_header" >+ responses: >+ "200": >+ description: A list of stockrotation rotas >+ schema: >+ type: array >+ items: >+ $ref: "../swagger.yaml#/definitions/rota" >+ "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: >+ catalogue: "1" >+ post: >+ x-mojo-to: StockRotation::Rotas#add >+ operationId: addRota >+ tags: >+ - stockrotation >+ summary: Add rota >+ parameters: >+ - name: body >+ in: body >+ description: A JSON object containing informations about the new hold >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/rota" >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Rota added >+ schema: >+ $ref: "../swagger.yaml#/definitions/rota" >+ "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: >+ stockrotation: "1" >+"/rotas/{rota_id}": >+ get: >+ x-mojo-to: StockRotation::Rotas#get >+ operationId: getRota >+ tags: >+ - stockrotation >+ summary: Get rota >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/rota_id_pp" >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A rota >+ schema: >+ $ref: "../swagger.yaml#/definitions/rota" >+ "404": >+ description: Rota 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: >+ catalogue: "1" >+ put: >+ x-mojo-to: StockRotation::Rotas#update >+ operationId: updateRota >+ tags: >+ - stockrotation >+ summary: Update rota >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/rota_id_pp" >+ - name: body >+ in: body >+ description: A rota object >+ required: true >+ schema: >+ $ref: "../swagger.yaml#/definitions/rota" >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A rota >+ schema: >+ $ref: "../swagger.yaml#/definitions/rota" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Rota 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: >+ stockrotation: "1" >+ delete: >+ x-mojo-to: StockRotation::Rotas#delete >+ operationId: deleteRota >+ tags: >+ - stockrotation >+ summary: Delete rota >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/rota_id_pp" >+ produces: >+ - application/json >+ responses: >+ "204": >+ description: Rota deleted >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Rota 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: >+ stockrotation: "1" > "/rotas/{rota_id}/stages/{stage_id}/position": > put: > x-mojo-to: StockRotation::Stage#move > operationId: moveStage > summary: Update stage > tags: >- - rotas >+ - stockrotation > parameters: > - name: rota_id > in: path >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 46966e40b2..376c66cb15 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -144,6 +144,8 @@ definitions: > $ref: ./definitions/renewals.yaml > return_claim: > $ref: ./definitions/return_claim.yaml >+ rota: >+ $ref: ./definitions/rota.yaml > search_filter: > $ref: ./definitions/search_filter.yaml > smtp_server: >@@ -487,6 +489,10 @@ paths: > $ref: "./paths/return_claims.yaml#/~1return_claims~1{claim_id}~1notes" > "/return_claims/{claim_id}/resolve": > $ref: "./paths/return_claims.yaml#/~1return_claims~1{claim_id}~1resolve" >+ "/rotas": >+ $ref: "./paths/rotas.yaml#/~1rotas" >+ "/rotas/{rota_id}": >+ $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}" > "/rotas/{rota_id}/stages/{stage_id}/position": > $ref: "./paths/rotas.yaml#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position" > /suggestions: >@@ -833,6 +839,12 @@ parameters: > name: x-koha-request-id > required: false > type: integer >+ rota_id_pp: >+ description: Rota internal identifier >+ in: path >+ name: rota_id >+ required: true >+ type: integer > search_filter_id_pp: > name: search_filter_id > in: path >@@ -1145,8 +1157,8 @@ tags: > - description: "Manage return claims\n" > name: return_claims > x-displayName: Return claims >- - description: "Manage rotas\n" >- name: rotas >+ - description: "Manage stock rotation\n" >+ name: stockrotation > x-displayName: Rotas > - description: "Manage search filters" > name: search_filters >-- >2.30.2
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 35430
:
159357
|
159358
|
159359
|
159360
|
159361
|
159362
|
159418
|
159419
|
159420
|
164134
|
164135
|
164136
|
165538
|
165539
|
165540
|
165541
|
168202
|
168203
|
168204