2020-04-28 11:27:59 -07:00
|
|
|
class Ajax::SubscriptionController < AjaxController
|
2020-04-18 16:45:50 -07:00
|
|
|
before_action :authenticate_user!
|
2015-04-20 18:12:11 -07:00
|
|
|
|
|
|
|
def subscribe
|
|
|
|
params.require :answer
|
2022-07-06 03:48:31 -07:00
|
|
|
@response[:status] = :okay
|
2023-03-04 11:42:51 -08:00
|
|
|
result = Subscription.subscribe(current_user, Answer.find(params[:answer]))
|
|
|
|
@response[:success] = result.present?
|
2015-04-20 18:12:11 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribe
|
|
|
|
params.require :answer
|
2022-07-06 03:48:31 -07:00
|
|
|
@response[:status] = :okay
|
2023-03-04 11:42:51 -08:00
|
|
|
result = Subscription.unsubscribe(current_user, Answer.find(params[:answer]))
|
|
|
|
@response[:success] = result&.destroyed? || false
|
2015-04-20 18:12:11 -07:00
|
|
|
end
|
|
|
|
end
|