diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 7d8ef241d..97034e12a 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -17,4 +17,8 @@ class Api::V1::BaseController < ApplicationController params[:per_page] = 100 if params[:per_page].to_i >100 end + def paginate_params + {:page => params[:page], :per_page => 20} + end + end diff --git a/app/controllers/api/v1/platforms_controller.rb b/app/controllers/api/v1/platforms_controller.rb index b27a98513..ae5c4b84f 100644 --- a/app/controllers/api/v1/platforms_controller.rb +++ b/app/controllers/api/v1/platforms_controller.rb @@ -8,14 +8,14 @@ class Api::V1::PlatformsController < Api::V1::BaseController def index @platforms = @platforms.accessible_by(current_ability, :related). - by_type(params[:type]).paginate(:page => params[:page], :per_page => 20) + by_type(params[:type]).paginate(paginate_params) end def show end def platforms_for_build - @platforms = Platform.main.opened.paginate(:page => params[:page], :per_page => 20) + @platforms = Platform.main.opened.paginate(paginate_params) render :index end @@ -36,4 +36,8 @@ class Api::V1::PlatformsController < Api::V1::BaseController end end + def members + @members = @platform.members.order('name').paginate(paginate_params) + end + end diff --git a/app/views/api/v1/platforms/members.json.jbuilder b/app/views/api/v1/platforms/members.json.jbuilder new file mode 100644 index 000000000..d491ca5ff --- /dev/null +++ b/app/views/api/v1/platforms/members.json.jbuilder @@ -0,0 +1,8 @@ +json.platform do |json| + json.(@platform, :id) + json.members @members do |json_members, member| + json_members.(member, :id) + json_members.type member.class.name + end +end +json.url members_api_v1_platform_path(@platform, :format => :json) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 098e7d9f5..3c1ea38fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,8 +20,13 @@ Rosa::Application.routes.draw do } end resources :arches, :only => [:index] - resources :platforms, :only => [:index, :show] do - collection { get :platforms_for_build } + resources :platforms, :only => [:index, :show, :update] do + collection { + get :platforms_for_build + } + member { + get :members + } end resources :repositories, :only => [:show] resources :projects, :only => [:show] do