list attachments of a WP via APIv3

pull/3032/head
Jan Sandbrink 10 years ago
parent b41539f9fb
commit 8585637981
  1. 38
      lib/api/v3/attachments/attachment_collection_representer.rb
  2. 47
      lib/api/v3/attachments/attachments_by_work_package_api.rb
  3. 4
      lib/api/v3/utilities/path_helper.rb
  4. 1
      lib/api/v3/work_packages/work_packages_api.rb
  5. 8
      spec/lib/api/v3/utilities/path_helper_spec.rb
  6. 0
      spec/requests/api/v3/attachments/attachment_resource_spec.rb

@ -0,0 +1,38 @@
#-- encoding: UTF-8
#-- 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.
#++
module API
module V3
module Attachments
class AttachmentCollectionRepresenter < ::API::Decorators::Collection
element_decorator ::API::V3::Attachments::AttachmentRepresenter
end
end
end
end

@ -0,0 +1,47 @@
#-- 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.
#++
require 'api/v3/attachments/attachment_collection_representer'
module API
module V3
module Attachments
class AttachmentsByWorkPackageAPI < ::API::OpenProjectAPI
resources :attachments do
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)
end
end
end
end
end
end

@ -50,6 +50,10 @@ module API
"#{root_path}attachments/#{id}"
end
def self.attachments_by_work_package(id)
"#{work_package(id)}/attachments"
end
def self.available_assignees(project_id)
"#{project(project_id)}/available_assignees"
end

@ -156,6 +156,7 @@ module API
mount ::API::V3::WorkPackages::WatchersAPI
mount ::API::V3::Relations::RelationsAPI
mount ::API::V3::WorkPackages::Form::FormAPI
mount ::API::V3::Attachments::AttachmentsByWorkPackageAPI
end
mount ::API::V3::WorkPackages::Schema::WorkPackageSchemasAPI

@ -63,6 +63,14 @@ describe ::API::V3::Utilities::PathHelper do
it { is_expected.to eql('/attachments/1') }
end
describe '#attachments_by_work_package' do
subject { helper.attachments_by_work_package 1 }
it_behaves_like 'api v3 path'
it { is_expected.to eql('/api/v3/work_packages/1/attachments') }
end
describe '#available_assignees' do
subject { helper.available_assignees 42 }

Loading…
Cancel
Save