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