From d99a2104ce0037a6821deff421baff37d8c6c890 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 16 Oct 2012 15:49:07 +0400 Subject: [PATCH] #692:added index action for Groups API --- app/controllers/api/v1/groups_controller.rb | 21 +++++++++++++++++++++ app/views/api/v1/groups/index.json.jbuilder | 15 +++++++++++++++ config/routes.rb | 8 ++++++++ 3 files changed, 44 insertions(+) create mode 100644 app/controllers/api/v1/groups_controller.rb create mode 100644 app/views/api/v1/groups/index.json.jbuilder diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb new file mode 100644 index 000000000..65ddbd5ab --- /dev/null +++ b/app/controllers/api/v1/groups_controller.rb @@ -0,0 +1,21 @@ +# -*- encoding : utf-8 -*- +class Api::V1::GroupsController < Api::V1::BaseController + + before_filter :authenticate_user! + skip_before_filter :authenticate_user!, :only => [:show] if APP_CONFIG['anonymous_access'] + load_and_authorize_resource :group + + def index + # accessible_by(current_ability) + @groups = current_user.groups.paginate(paginate_params) + end + + def show + end + + def update + + end + + +end \ No newline at end of file diff --git a/app/views/api/v1/groups/index.json.jbuilder b/app/views/api/v1/groups/index.json.jbuilder new file mode 100644 index 000000000..485ffdb1b --- /dev/null +++ b/app/views/api/v1/groups/index.json.jbuilder @@ -0,0 +1,15 @@ +json.groups @groups do |json, group| + json.(group, :id, :uname, :own_projects_count, :description) + json.created_at group.created_at.to_i + json.updated_at group.updated_at.to_i + json.owner do |json_owner| + json_owner.(group.owner, :id, :name) + json_owner.type 'User' + json_owner.url api_v1_user_path(group.owner.id, :format => :json) + end + json.avatar_url avatar_url(group, :big) + json.url api_v1_group_path(group.id, :format => :json) + json.html_url group_path(group.uname) +end + +json.url api_v1_groups_path(:format => :json) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1e51693f0..bd1691c70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,14 @@ Rosa::Application.routes.draw do put :notifiers } end + resources :groups, :only => [:index, :show, :update, :create, :destroy] do + member { + get :members + put :add_member + delete :remove_member + put :update_member + } + end end end