make collection representer explicitly unpaginated

pull/3334/head
Jan Sandbrink 9 years ago
parent c4f9e6605b
commit b332ef06aa
  1. 6
      lib/api/decorators/unpaginated_collection.rb
  2. 2
      lib/api/v3/attachments/attachment_collection_representer.rb
  3. 4
      lib/api/v3/attachments/attachments_by_work_package_api.rb
  4. 4
      lib/api/v3/categories/categories_by_project_api.rb
  5. 2
      lib/api/v3/categories/category_collection_representer.rb
  6. 4
      lib/api/v3/priorities/priorities_api.rb
  7. 2
      lib/api/v3/priorities/priority_collection_representer.rb
  8. 5
      lib/api/v3/projects/available_assignees_api.rb
  9. 5
      lib/api/v3/projects/available_responsibles_api.rb
  10. 2
      lib/api/v3/projects/project_collection_representer.rb
  11. 4
      lib/api/v3/repositories/revisions_by_work_package_api.rb
  12. 2
      lib/api/v3/repositories/revisions_collection_representer.rb
  13. 2
      lib/api/v3/statuses/status_collection_representer.rb
  14. 4
      lib/api/v3/statuses/statuses_api.rb
  15. 2
      lib/api/v3/types/type_collection_representer.rb
  16. 4
      lib/api/v3/types/types_api.rb
  17. 1
      lib/api/v3/types/types_by_project_api.rb
  18. 2
      lib/api/v3/users/user_collection_representer.rb
  19. 4
      lib/api/v3/versions/projects_by_version_api.rb
  20. 2
      lib/api/v3/versions/version_collection_representer.rb
  21. 1
      lib/api/v3/versions/versions_by_project_api.rb
  22. 4
      lib/api/v3/work_packages/watchers_api.rb
  23. 3
      lib/api/v3/work_packages/work_package_representer.rb
  24. 4
      spec/lib/api/v3/categories/category_collection_representer_spec.rb
  25. 4
      spec/lib/api/v3/priorities/priority_collection_representer_spec.rb
  26. 4
      spec/lib/api/v3/projects/project_collection_representer_spec.rb
  27. 32
      spec/lib/api/v3/statuses/shared/status_collection_representer.rb
  28. 8
      spec/lib/api/v3/statuses/status_collection_representer_spec.rb
  29. 4
      spec/lib/api/v3/users/user_collection_representer_spec.rb
  30. 4
      spec/lib/api/v3/versions/version_collection_representer_spec.rb

@ -32,13 +32,13 @@ require 'roar/json/hal'
module API
module Decorators
class Collection < Roar::Decorator
class UnpaginatedCollection < Roar::Decorator
include Roar::JSON::HAL
include Roar::Hypermedia
include API::Utilities::UrlHelper
def initialize(models, total, self_link, context: {})
@total = total
def initialize(models, self_link, context: {})
@total = models.count
@self_link = self_link
@context = context

@ -30,7 +30,7 @@
module API
module V3
module Attachments
class AttachmentCollectionRepresenter < ::API::Decorators::Collection
class AttachmentCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Attachments::AttachmentRepresenter
end
end

@ -53,9 +53,7 @@ module API
get do
self_path = api_v3_paths.attachments_by_work_package(@work_package.id)
attachments = @work_package.attachments
AttachmentCollectionRepresenter.new(attachments,
attachments.count,
self_path)
AttachmentCollectionRepresenter.new(attachments, self_path)
end
post do

@ -41,9 +41,7 @@ module API
get do
self_link = api_v3_paths.categories(@project.identifier)
CategoryCollectionRepresenter.new(@categories,
@categories.count,
self_link)
CategoryCollectionRepresenter.new(@categories, self_link)
end
end
end

@ -30,7 +30,7 @@
module API
module V3
module Categories
class CategoryCollectionRepresenter < ::API::Decorators::Collection
class CategoryCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Categories::CategoryRepresenter
end
end

@ -42,9 +42,7 @@ module API
end
get do
PriorityCollectionRepresenter.new(@priorities,
@priorities.count,
api_v3_paths.priorities)
PriorityCollectionRepresenter.new(@priorities, api_v3_paths.priorities)
end
route_param :id do

@ -30,7 +30,7 @@
module API
module V3
module Priorities
class PriorityCollectionRepresenter < ::API::Decorators::Collection
class PriorityCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Priorities::PriorityRepresenter
end
end

@ -35,11 +35,8 @@ module API
resource :available_assignees do
get do
available_assignees = @project.possible_assignees
total = available_assignees.count
self_link = api_v3_paths.available_assignees(@project.id)
Users::UserCollectionRepresenter.new(available_assignees,
total,
self_link)
Users::UserCollectionRepresenter.new(available_assignees, self_link)
end
end
end

@ -35,11 +35,8 @@ module API
resource :available_responsibles do
get do
available_responsibles = @project.possible_responsibles
total = available_responsibles.count
self_link = api_v3_paths.available_responsibles(@project.id)
Users::UserCollectionRepresenter.new(available_responsibles,
total,
self_link)
Users::UserCollectionRepresenter.new(available_responsibles, self_link)
end
end
end

@ -35,7 +35,7 @@ require 'roar/json/hal'
module API
module V3
module Projects
class ProjectCollectionRepresenter < ::API::Decorators::Collection
class ProjectCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Projects::ProjectRepresenter
end
end

@ -41,9 +41,7 @@ module API
self_path = api_v3_paths.work_package_revisions(work_package.id)
revisions = work_package.changesets
RevisionsCollectionRepresenter.new(revisions,
revisions.count,
self_path)
RevisionsCollectionRepresenter.new(revisions, self_path)
end
end
end

@ -30,7 +30,7 @@
module API
module V3
module Repositories
class RevisionsCollectionRepresenter < ::API::Decorators::Collection
class RevisionsCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Repositories::RevisionRepresenter
end
end

@ -30,7 +30,7 @@
module API
module V3
module Statuses
class StatusCollectionRepresenter < ::API::Decorators::Collection
class StatusCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Statuses::StatusRepresenter
end
end

@ -42,9 +42,7 @@ module API
end
get do
StatusCollectionRepresenter.new(@statuses,
@statuses.count,
api_v3_paths.statuses)
StatusCollectionRepresenter.new(@statuses, api_v3_paths.statuses)
end
route_param :id do

@ -30,7 +30,7 @@
module API
module V3
module Types
class TypeCollectionRepresenter < ::API::Decorators::Collection
class TypeCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Types::TypeRepresenter
end
end

@ -41,9 +41,7 @@ module API
get do
types = Type.all
TypeCollectionRepresenter.new(types,
types.count,
api_v3_paths.types)
TypeCollectionRepresenter.new(types, api_v3_paths.types)
end
namespace ':id' do

@ -41,7 +41,6 @@ module API
get do
types = @project.types
TypeCollectionRepresenter.new(types,
types.count,
api_v3_paths.types_by_project(@project.id),
context: { current_user: current_user })
end

@ -30,7 +30,7 @@
module API
module V3
module Users
class UserCollectionRepresenter < ::API::Decorators::Collection
class UserCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Users::UserRepresenter
end
end

@ -43,9 +43,7 @@ module API
get do
path = api_v3_paths.projects_by_version @version.id
Projects::ProjectCollectionRepresenter.new(@projects,
@projects.count,
path)
Projects::ProjectCollectionRepresenter.new(@projects, path)
end
end
end

@ -35,7 +35,7 @@ require 'roar/json/hal'
module API
module V3
module Versions
class VersionCollectionRepresenter < ::API::Decorators::Collection
class VersionCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
element_decorator ::API::V3::Versions::VersionRepresenter
end
end

@ -42,7 +42,6 @@ module API
get do
VersionCollectionRepresenter.new(@versions,
@versions.count,
api_v3_paths.versions_by_project(@project.id),
context: { current_user: current_user })
end

@ -34,11 +34,9 @@ module API
authorize(:add_work_package_watchers, context: @work_package.project)
available_watchers = @work_package.possible_watcher_users
total = available_watchers.count
self_link = api_v3_paths.available_watchers(@work_package.id)
::API::V3::Users::UserCollectionRepresenter.new(available_watchers,
total,
self_link)
end
@ -46,10 +44,8 @@ module API
helpers do
def watchers_collection
watchers = @work_package.watcher_users
total = watchers.count
self_link = api_v3_paths.work_package_watchers(@work_package.id)
Users::UserCollectionRepresenter.new(watchers,
total,
self_link,
context: { current_user: current_user })
end

@ -321,14 +321,12 @@ module API
def watchers
# TODO/LEGACY: why do we need to ensure a specific order here?
watchers = represented.watcher_users.order(User::USER_FORMATS_STRUCTURE[Setting.user_format])
total = watchers.count
self_link = api_v3_paths.work_package_watchers(represented.id)
# FIXME/LEGACY: we pass the WP as context?!? that makes a difference!!!
# tl;dr: the embedded user representer must not be better than any other user representer
context = { current_user: current_user, work_package: represented }
Users::UserCollectionRepresenter.new(watchers,
total,
self_link,
context: context)
end
@ -337,7 +335,6 @@ module API
self_path = api_v3_paths.attachments_by_work_package(represented.id)
attachments = represented.attachments
::API::V3::Attachments::AttachmentCollectionRepresenter.new(attachments,
attachments.count,
self_path)
end

@ -30,11 +30,11 @@ require 'spec_helper'
describe ::API::V3::Categories::CategoryCollectionRepresenter do
let(:categories) { FactoryGirl.build_list(:category, 3) }
let(:representer) { described_class.new(categories, 42, '/api/v3/projects/1/categories') }
let(:representer) { described_class.new(categories, '/api/v3/projects/1/categories') }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'API V3 collection decorated', 42, 3, 'projects/1/categories', 'Category'
it_behaves_like 'API V3 collection decorated', 3, 3, 'projects/1/categories', 'Category'
end
end

@ -30,11 +30,11 @@ require 'spec_helper'
describe ::API::V3::Priorities::PriorityCollectionRepresenter do
let(:priorities) { FactoryGirl.build_list(:priority, 3) }
let(:representer) { described_class.new(priorities, 42, '/api/v3/priorities') }
let(:representer) { described_class.new(priorities, '/api/v3/priorities') }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'API V3 collection decorated', 42, 3, 'priorities', 'Priority'
it_behaves_like 'API V3 collection decorated', 3, 3, 'priorities', 'Priority'
end
end

@ -31,11 +31,11 @@ require 'spec_helper'
describe ::API::V3::Projects::ProjectCollectionRepresenter do
let(:self_link) { '/api/v3/versions/1/projects' }
let(:projects) { FactoryGirl.build_list(:project, 3) }
let(:representer) { described_class.new(projects, 42, self_link) }
let(:representer) { described_class.new(projects, self_link) }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'API V3 collection decorated', 42, 3, 'versions/1/projects', 'Project'
it_behaves_like 'API V3 collection decorated', 3, 3, 'versions/1/projects', 'Project'
end
end

@ -1,32 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
RSpec.shared_context 'status collection representer' do |self_link|
let(:statuses) { FactoryGirl.build_list(:status, 3) }
let(:representer) { described_class.new(statuses, 42, self_link) }
end

@ -27,14 +27,16 @@
#++
require 'spec_helper'
require 'lib/api/v3/statuses/shared/status_collection_representer'
describe ::API::V3::Statuses::StatusCollectionRepresenter do
include_context 'status collection representer', '/api/v3/statuses'
include API::V3::Utilities::PathHelper
let(:statuses) { FactoryGirl.build_list(:status, 3) }
let(:representer) { described_class.new(statuses, api_v3_paths.statuses) }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'API V3 collection decorated', 42, 3, 'statuses', 'Status'
it_behaves_like 'API V3 collection decorated', 3, 3, 'statuses', 'Status'
end
end

@ -35,11 +35,11 @@ describe ::API::V3::Users::UserCollectionRepresenter do
created_on: Time.now,
updated_on: Time.now)
}
let(:representer) { described_class.new(users, 42, '/api/v3/work_package/1/watchers') }
let(:representer) { described_class.new(users, '/api/v3/work_package/1/watchers') }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'API V3 collection decorated', 42, 3, 'work_package/1/watchers', 'User'
it_behaves_like 'API V3 collection decorated', 3, 3, 'work_package/1/watchers', 'User'
end
end

@ -33,11 +33,11 @@ describe ::API::V3::Versions::VersionCollectionRepresenter do
let(:versions) { FactoryGirl.build_list(:version, 3) }
let(:user) { FactoryGirl.build_stubbed(:user) }
let(:context) { { current_user: user } }
let(:representer) { described_class.new(versions, 42, self_link, context: context) }
let(:representer) { described_class.new(versions, self_link, context: context) }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'API V3 collection decorated', 42, 3, 'projects/1/versions', 'Version'
it_behaves_like 'API V3 collection decorated', 3, 3, 'projects/1/versions', 'Version'
end
end

Loading…
Cancel
Save