2020-04-28 20:27:59 +02:00
|
|
|
class Ajax::SubscriptionController < AjaxController
|
2020-04-19 01:45:50 +02:00
|
|
|
before_action :authenticate_user!
|
2015-04-21 03:12:11 +02:00
|
|
|
|
|
|
|
def subscribe
|
|
|
|
params.require :answer
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = 418
|
|
|
|
@response[:message] = I18n.t('messages.subscription.torpedo')
|
2015-04-21 03:12:11 +02:00
|
|
|
state = Subscription.subscribe(current_user, Answer.find(params[:answer])).nil?
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = state == false
|
2015-04-21 03:12:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribe
|
|
|
|
params.require :answer
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = 418
|
|
|
|
@response[:message] = I18n.t('messages.subscription.torpedo')
|
2015-04-21 03:12:11 +02:00
|
|
|
state = Subscription.unsubscribe(current_user, Answer.find(params[:answer])).nil?
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = state == false
|
2015-04-21 03:12:11 +02:00
|
|
|
end
|
|
|
|
end
|