Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Add pagination to commands collection
Browse files Browse the repository at this point in the history
The commands collection, which can grow quite lengthy, currently does not
allow any pagination. This provides the "start" and "limit" query arguments,
which are present for many other collections.
  • Loading branch information
Scott McClellan committed Dec 12, 2015
1 parent daad0cd commit 7c7b9cf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,9 @@ def render_template(name)
#
# @todo danielp 2013-06-26: this should be some sort of discovery, not a
# hand-coded list, but ... it will do, for now.
COLLECTIONS = [:brokers, :repos, :tags, :policies, [:nodes, {'start' => {"type" => "number"}, 'limit' => {"type" => "number"}}],
:tasks, :commands,
COLLECTIONS = [:brokers, :repos, :tags, :policies,
[:nodes, {'start' => {"type" => "number"}, 'limit' => {"type" => "number"}}],
:tasks, [:commands, {'start' => {'type' => 'number'}, 'limit' => {'type' => 'number'}}],
[:events, {'start' => {"type" => "number"}, 'limit' => {"type" => "number"}}], :hooks]

#
Expand Down Expand Up @@ -692,7 +693,18 @@ def render_template(name)
end

get '/api/collections/commands' do
collection_view Razor::Data::Command.order(:submitted_at).order(:id), 'commands'
limit = params[:limit]
start = params[:start]

raise TypeError, _('limit must be a number, but was %{limit}') %
{limit: limit} unless limit.to_i.to_s == limit or limit.nil?
raise TypeError, _('start must be a number, but was %{start}') %
{start: start} unless start.to_i.to_s == start or start.nil?
limit = Integer(limit) if limit
start = Integer(start) if start

collection_view Razor::Data::Command.order(:submitted_at).order(:id),
'commands', limit: limit, start: start, facts: true
end

get '/api/collections/commands/:id' do
Expand Down

0 comments on commit 7c7b9cf

Please sign in to comment.