From 00147bb48a8d09f7067b74cc391783f7806ca2ca Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 27 Aug 2015 13:20:16 +0200 Subject: [PATCH] Bug 14749: Add API route /v1/topissues See Swagger specification for documentation --- Koha/REST/V1/TopIssues.pm | 27 ++++++++++++++ api/v1/swagger.json | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 Koha/REST/V1/TopIssues.pm diff --git a/Koha/REST/V1/TopIssues.pm b/Koha/REST/V1/TopIssues.pm new file mode 100644 index 0000000..61aad7e --- /dev/null +++ b/Koha/REST/V1/TopIssues.pm @@ -0,0 +1,27 @@ +package Koha::REST::V1::TopIssues; + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use C4::Context; +use C4::Circulation; + +sub get_top_issues { + my ($c, $args, $cb) = @_; + + my $req = $c->req; + my %params = ( + count => $req->param('count'), + branch => $req->param('branch'), + itemtype => $req->param('itemtype'), + ccode => $req->param('ccode'), + newness => $req->param('newness'), + ); + + my @results = GetTopIssues(\%params); + + $c->$cb(\@results, 200); +} + +1; diff --git a/api/v1/swagger.json b/api/v1/swagger.json index 9672f15..ea26aa7 100644 --- a/api/v1/swagger.json +++ b/api/v1/swagger.json @@ -63,6 +63,99 @@ } } } + }, + "/topissues": { + "get": { + "x-mojo-controller": "Koha::REST::V1::TopIssues", + "operationId": "get_top_issues", + "tags": ["issues"], + "parameters": [ + { + "name": "count", + "in": "query", + "type": "integer", + "minimum": 1, + "description": "Number of titles to retrieve" + }, + { + "name": "branch", + "in": "query", + "type": "string", + "description": "Filter by branch code" + }, + { + "name": "itemtype", + "in": "query", + "type": "string", + "description": "Filter by item type" + }, + { + "name": "ccode", + "in": "query", + "type": "string", + "description": "Filter by collection code" + }, + { + "name": "newness", + "in": "query", + "type": "integer", + "minimum": 1, + "description": "Filter by newness (in days)" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A borrower", + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "count": { + "description": "Number of issues for this title" + }, + "copyrightdate": { + "description": "Copyright date" + }, + "ccode": { + "description": "Collection code" + }, + "itemtype": { + "description": "Item type" + }, + "place": { + "description": "Publication place" + }, + "author": { + "description": "Author" + }, + "size": { + "description": "Material size" + }, + "biblionumber": { + "description": "Biblio internal identifier" + }, + "title": { + "description": "Title" + }, + "publicationyear": { + "description": "Publication year" + }, + "publishercode": { + "description": "Publisher code" + }, + "pages": { + "description": "Number of pages" + } + } + } + } + } + } + } } }, "definitions": { -- 1.9.1