2012-04-10 14:06:46 +00:00
|
|
|
class GroupsController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
|
|
|
# GET /groups
|
|
|
|
def index
|
|
|
|
@groups = Group.all
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @groups
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /groups/1
|
|
|
|
def show
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @group
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /groups
|
|
|
|
def create
|
|
|
|
@group = Group.new(params[:group])
|
|
|
|
@group.created_by_id = current_user.id
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @group.save
|
|
|
|
render :json => @group, :status => :created
|
|
|
|
else
|
|
|
|
render :json => @group.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /groups/1
|
|
|
|
def update
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @group.update_attributes(params[:group])
|
|
|
|
render :json => @group, :status => :ok
|
|
|
|
else
|
|
|
|
render :json => @group.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /groups/1
|
|
|
|
def destroy
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
@group.destroy
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
head :ok
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|