Created basic structure for Work packages API

pull/1435/head
Marek Takac 11 years ago
parent 00f3b7a291
commit cb464d9329
  1. 61
      app/api/work_packages/work_packages.rb

@ -2,54 +2,49 @@ module WorkPackages
class API < Grape::API
resources :work_packages do
params do
optional :page, type: Integer, default: 1
optional :per_page, type: Integer, default: 100
optional :filters, type: String
optional :sort_expression, type: String
optional :embedded, type: String
end
get do
work_packages = WorkPackage.all
'list all work packages'
end
get ':id' do
work_package = WorkPackage.find(params[:id])
authorize work_package, :show?
resource = WorkPackageMapper.new(work_package, 'rest').to_resource
binding.pry
Yaks::HalSerializer.new(resource).to_hal.to_json
post do
'create new work package(s)'
end
patch ':id' do
"work package update"
patch do
'batch update work packages'
end
delete :':id' do
"work package delete"
delete do
'batch delete work packages'
end
patch do
"work packages batch update"
params do
requires :id, type: Integer, desc: 'Work package id.'
end
namespace ':id' do
delete do
"work packages batch delete"
end
end
before do
@work_package = WorkPackage.find(params[:id])
end
get do
'show a work package'
end
resources :projects do
namespace ':project_id' do
get :work_packages do
project = Project.find(params[:project_id])
project.work_packages
end
put do
'update a work package (provide whole resource)'
end
patch do
@work_package
end
post :work_packages do
"create work packages for project (batch and single)"
end
delete do
'delete a work package'
end
end
end
end
end

Loading…
Cancel
Save