Skip to content

Commit

Permalink
create separate route for adding a customer to a group
Browse files Browse the repository at this point in the history
  • Loading branch information
data-doge committed Apr 20, 2016
1 parent 718d3a7 commit 48054f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def index
def create
group = Group.create(group_params)
group.add_admin(current_user)
group.add_customer(current_user.email)
render json: [group]
end

Expand All @@ -32,6 +31,17 @@ def update
render json: [group]
end

api :POST, '/groups/:id/add_customer', 'Add a credit card that pays for the group'
def add_customer
group = Group.find(params[:id])
if current_user.is_admin_for(group)
group.add_customer(current_user.email)
render json: [group]
else
render nothing: true, status: 403
end
end

api :POST, '/groups/:id/add_card', 'Add a credit card that pays for the group'
def add_card
group = Group.find(params[:id])
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

resources :groups, only: [:index, :show, :create, :update] do
member do
post :add_customer
post :add_card
post :extend_trial
end
Expand Down

0 comments on commit 48054f1

Please sign in to comment.