2020-04-28 20:27:59 +02:00
|
|
|
class Ajax::SmileController < AjaxController
|
2014-11-30 20:31:22 +01:00
|
|
|
def create
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
answer = Answer.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.smile answer
|
2022-06-12 23:26:29 +02:00
|
|
|
rescue Errors::Base => e
|
|
|
|
@response[:status] = e.code
|
2022-06-13 11:48:49 +02:00
|
|
|
@response[:message] = I18n.t(e.locale_tag)
|
2022-06-12 23:26:29 +02:00
|
|
|
return
|
2020-04-28 20:32:36 +02:00
|
|
|
rescue => e
|
2021-12-28 18:32:03 +01:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :fail
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".error")
|
2014-11-30 20:31:22 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = true
|
2014-11-30 20:31:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
answer = Answer.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.unsmile answer
|
2020-04-28 20:32:36 +02:00
|
|
|
rescue => e
|
2021-12-28 18:32:03 +01:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :fail
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".error")
|
2014-11-30 20:31:22 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = true
|
2014-11-30 20:31:22 +01:00
|
|
|
end
|
2015-05-04 03:39:41 +02:00
|
|
|
|
|
|
|
def create_comment
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
comment = Comment.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
2022-02-27 15:43:19 +01:00
|
|
|
current_user.smile comment
|
2022-06-12 23:26:29 +02:00
|
|
|
rescue Errors::Base => e
|
|
|
|
@response[:status] = e.code
|
2022-06-13 11:48:49 +02:00
|
|
|
@response[:message] = I18n.t(e.locale_tag)
|
2022-06-12 23:26:29 +02:00
|
|
|
return
|
2020-04-28 20:32:36 +02:00
|
|
|
rescue => e
|
2021-12-28 18:32:03 +01:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :fail
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".error")
|
2015-05-04 03:39:41 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = true
|
2015-05-04 03:39:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_comment
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
comment = Comment.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
2022-02-27 15:43:19 +01:00
|
|
|
current_user.unsmile comment
|
2020-04-28 20:32:36 +02:00
|
|
|
rescue => e
|
2021-12-28 18:32:03 +01:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :fail
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".error")
|
2015-05-04 03:39:41 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
2022-07-06 09:44:43 +02:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = true
|
2015-05-04 03:39:41 +02:00
|
|
|
end
|
2014-11-30 20:31:22 +01:00
|
|
|
end
|