From 1593845ddbeafc640dbbb2756e37163c77af4ef4 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 | 28 +++++++++++ api/v1/swagger/paths.json | 3 ++ api/v1/swagger/paths/topissues.json | 95 +++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 Koha/REST/V1/TopIssues.pm create mode 100644 api/v1/swagger/paths/topissues.json diff --git a/Koha/REST/V1/TopIssues.pm b/Koha/REST/V1/TopIssues.pm new file mode 100644 index 0000000000..f5ba5c89c7 --- /dev/null +++ b/Koha/REST/V1/TopIssues.pm @@ -0,0 +1,28 @@ +package Koha::REST::V1::TopIssues; + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use C4::Context; +use C4::Circulation; + +sub list { + my $c = shift->openapi->valid_input or return; + my $args = $c->req->params->to_hash // {}; + + my $req = $c->req; + my %params = ( + count => $args->{'count'}, + branch => $args->{'branch'}, + itemtype => $args->{'itemtype'}, + ccode => $args->{'ccode'}, + newness => $args->{'newness'}, + ); + + my @results = GetTopIssues(\%params); + + return $c->render(status => 200, openapi => \@results); +} + +1; diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json index 9c3a6d2efd..79075aecf2 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -25,5 +25,8 @@ }, "/illrequests": { "$ref": "paths/illrequests.json#/~1illrequests" + }, + "/topissues": { + "$ref": "paths/topissues.json#/~1topissues" } } diff --git a/api/v1/swagger/paths/topissues.json b/api/v1/swagger/paths/topissues.json new file mode 100644 index 0000000000..ebab73dd93 --- /dev/null +++ b/api/v1/swagger/paths/topissues.json @@ -0,0 +1,95 @@ +{ + "/topissues": { + "get": { + "x-mojo-to": "TopIssues#list", + "operationId": "listTopIssues", + "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" + } + } + } + } + } + } + } + } +} -- 2.14.2