v3: add pagination and sortability to repo endpoints
This commit is contained in:
parent
2ebfa1d85b
commit
571af14067
|
@ -1,6 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Queries::Repositories < Query
|
||||
params :active, :private, prefix: :repository
|
||||
sortable_by :id, :github_id, :owner_name, :name, active: sort_condition(:active)
|
||||
|
||||
def for_member(user)
|
||||
all.joins(:users).where(users: user_condition(user), invalidated_at: nil)
|
||||
|
@ -27,7 +28,7 @@ module Travis::API::V3
|
|||
|
||||
list = list.includes(default_branch: :last_build)
|
||||
list = list.includes(default_branch: { last_build: :commit }) if includes? 'build.commit'.freeze
|
||||
list
|
||||
sort list
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ module Travis::API::V3
|
|||
class Services::Owner::Repositories < Service
|
||||
params :active, :private, prefix: :repository
|
||||
result_type :repositories
|
||||
paginate(default_limit: 100)
|
||||
|
||||
def run!
|
||||
unfiltered = query(:repositories).for_owner(find(:owner))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repositories::ForCurrentUser < Service
|
||||
params :active, :private, prefix: :repository
|
||||
paginate(default_limit: 100)
|
||||
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in?
|
||||
|
|
|
@ -64,7 +64,7 @@ describe Travis::API::V3::ServiceIndex do
|
|||
|
||||
describe "for_current_user action" do
|
||||
let(:action) { resource.fetch("actions").fetch("for_current_user") }
|
||||
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}repos{?active,include,private,repository.active,repository.private}") }
|
||||
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}repos{?active,include,limit,offset,private,repository.active,repository.private,sort_by}") }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,6 +18,22 @@ describe Travis::API::V3::Services::Owner::Repositories do
|
|||
"@type" => "repositories",
|
||||
"@href" => "/v3/owner/svenfuchs/repos",
|
||||
"@representation" => "standard",
|
||||
"@pagination" => {
|
||||
"limit" => 100,
|
||||
"offset" => 0,
|
||||
"count" => 1,
|
||||
"is_first" => true,
|
||||
"is_last" => true,
|
||||
"next" => nil,
|
||||
"prev" => nil,
|
||||
"first" => {
|
||||
"@href" => "/v3/owner/svenfuchs/repos",
|
||||
"offset" => 0,
|
||||
"limit" => 100},
|
||||
"last" => {
|
||||
"@href" => "/v3/owner/svenfuchs/repos",
|
||||
"offset" => 0,
|
||||
"limit" => 100}},
|
||||
"repositories" => [{
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
|
|
|
@ -17,7 +17,23 @@ describe Travis::API::V3::Services::Repositories::ForCurrentUser do
|
|||
example { expect(JSON.load(body)).to be == {
|
||||
"@type" => "repositories",
|
||||
"@href" => "/v3/repos",
|
||||
"@representation" => "standard",
|
||||
"@representation" => "standard",
|
||||
"@pagination" => {
|
||||
"limit" => 100,
|
||||
"offset" => 0,
|
||||
"count" => 1,
|
||||
"is_first" => true,
|
||||
"is_last" => true,
|
||||
"next" => nil,
|
||||
"prev" => nil,
|
||||
"first" => {
|
||||
"@href" => "/v3/repos",
|
||||
"offset" => 0,
|
||||
"limit" => 100},
|
||||
"last" => {
|
||||
"@href" => "/v3/repos",
|
||||
"offset" => 0,
|
||||
"limit" => 100}},
|
||||
"repositories" => [{
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
|
|
Loading…
Reference in New Issue
Block a user