From d4f46ff9fe708d8f6e1eb642a442df7895255815 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Aug 2022 11:37:55 +0100 Subject: [PATCH] Bug 31028: Add resolution endpoint This patch adds a /resolve endpoint to the catalog concerns endpoints. --- Koha/Catalog/Concern.pm | 36 +++++++++++++++++ Koha/REST/V1/Catalog/Concerns.pm | 47 +++++++++++++++++++++- api/v1/swagger/definitions/resolution.yaml | 10 +++++ api/v1/swagger/paths/catalog_concerns.yaml | 43 ++++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 ++ 5 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 api/v1/swagger/definitions/resolution.yaml diff --git a/Koha/Catalog/Concern.pm b/Koha/Catalog/Concern.pm index e246c6f742..a4ab05615e 100644 --- a/Koha/Catalog/Concern.pm +++ b/Koha/Catalog/Concern.pm @@ -69,6 +69,42 @@ sub biblio { return Koha::Biblio->_new_from_dbic( $rs ); } +=head3 resolve + + $concern = $concern->resolve( + { + resolver => $user, + notify => $boolean, + message => $message + } + ); + +Method to mark a concern as resolved + +=cut + +sub resolve { + my ( $self, $params ) = @_; + + my $resolver = $params->{resolver}; + my $message = $params->{message}; + + $self->set( + { + resolved_date => \'NOW()', + resolver_id => $resolver->borrowernumber, + resolution_message => $message + } + )->store(); + + # Optionally add to message_queue here to notify reporter + if ( $params->{notify} ) { + + } + + return $self; +} + =head2 Internal methods =cut diff --git a/Koha/REST/V1/Catalog/Concerns.pm b/Koha/REST/V1/Catalog/Concerns.pm index 2ce15bfd79..a7b8760f5c 100644 --- a/Koha/REST/V1/Catalog/Concerns.pm +++ b/Koha/REST/V1/Catalog/Concerns.pm @@ -99,8 +99,10 @@ sub update { my $concern = Koha::Catalog::Concerns->find( $c->validation->param('concern_id') ); if ( not defined $concern ) { - return $c->render( status => 404, - openapi => { error => "Object not found" } ); + return $c->render( + status => 404, + openapi => { error => "Object not found" } + ); } return try { @@ -138,4 +140,45 @@ sub delete { }; } +=head3 resolve + +Resolve action, sets the catalog concern to resolved and optionally sends the submitter a notification. + +=cut + +sub resolve { + my $c = shift->openapi->valid_input or return; + + my $concern = + Koha::Catalog::Concerns->find( $c->validation->param('concern_id') ); + + if ( not defined $concern ) { + return $c->render( + status => 404, + openapi => { error => "Object not found" } + ); + } + + my $resolver = $c->stash('koha.user'); + my $body = $c->validation->param('body'); + my $notify = $body->{notify}; + my $message = $body->{message}; + return try { + $concern->resolve( + { + resolver => $resolver, + notify => $notify, + message => $message + } + ); + return $c->render( + status => 204, + openapi => q{} + ); + } + catch { + $c->unhandled_exception($_); + } +} + 1; diff --git a/api/v1/swagger/definitions/resolution.yaml b/api/v1/swagger/definitions/resolution.yaml new file mode 100644 index 0000000000..62b7f59a8e --- /dev/null +++ b/api/v1/swagger/definitions/resolution.yaml @@ -0,0 +1,10 @@ +--- +type: object +properties: + message: + description: Resolution message + type: string + notify: + description: Signal to notify the user + type: boolean +additionalProperties: true diff --git a/api/v1/swagger/paths/catalog_concerns.yaml b/api/v1/swagger/paths/catalog_concerns.yaml index 2dd3b479da..2b4c813b01 100644 --- a/api/v1/swagger/paths/catalog_concerns.yaml +++ b/api/v1/swagger/paths/catalog_concerns.yaml @@ -210,6 +210,49 @@ x-koha-authorization: permissions: editcatalogue: edit_catalogue +"/catalog/concerns/{concern_id}/resolve": + post: + x-mojo-to: Catalog::Concerns#resolve + operationId: resolveConcern + tags: + - concerns + summary: Resolve the concern + parameters: + - $ref: "../swagger.yaml#/parameters/concern_id_pp" + - name: body + in: body + description: A resolution object + required: true + schema: + $ref: "../swagger.yaml#/definitions/resolution" + produces: + - application/json + responses: + "204": + description: Concern resolved + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: Concern 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: + editcatalogue: edit_catalogue /public/catalog/concerns: post: x-mojo-to: Catalog::Concerns#add diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 806ab7009f..19e1cf50f5 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -68,6 +68,8 @@ definitions: $ref: ./definitions/renewal.yaml renewals: $ref: ./definitions/renewals.yaml + resolution: + $ref: ./definitions/resolution.yaml return_claim: $ref: ./definitions/return_claim.yaml smtp_server: @@ -131,6 +133,8 @@ paths: $ref: "./paths/catalog_concerns.yaml#/~1catalog~1concerns" "/catalog/concerns/{concern_id}": $ref: "./paths/catalog_concerns.yaml#/~1catalog~1concerns~1{concern_id}" + "/catalog/concerns/{concern_id}/resolve": + $ref: "./paths/catalog_concerns.yaml#/~1catalog~1concerns~1{concern_id}~1resolve" /checkouts: $ref: ./paths/checkouts.yaml#/~1checkouts "/checkouts/{checkout_id}": -- 2.20.1