Skip to content

Commit

Permalink
feat: add subscription cancel endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
castrolem committed Oct 14, 2019
1 parent a49f71f commit 0f077ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

class SubscriptionsController < ApplicationController
before_action :set_user, only: %i[destroy]

# DELETE /user/:user_id/subscription
# DELETE /user/:user_id/subscription.json
def destroy
head :not_authorized unless current_user == @user

subscription = @user.subscription

subscription.active = false
if subscription.save
head :ok
else
head :bad_request
end
end

private

def set_user
@user = User.find(params[:user_id])
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
resources :users, only: %i[show new edit update create destroy] do
resource :streak, only: %i[show]
resources :cards, only: %i[index destroy]
resource :subscription, only: %i[destroy]
end

get '/login' => 'sessions#login'
Expand Down

0 comments on commit 0f077ef

Please sign in to comment.