2020-04-28 11:27:59 -07:00
|
|
|
class Ajax::FriendController < AjaxController
|
2014-11-30 05:45:32 -08:00
|
|
|
def create
|
2014-11-30 06:13:37 -08:00
|
|
|
params.require :screen_name
|
|
|
|
|
|
|
|
target_user = User.find_by_screen_name(params[:screen_name])
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.follow target_user
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue => e
|
|
|
|
NewRelic::Agent.notice_error(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :fail
|
|
|
|
@response[:message] = I18n.t('messages.friend.create.fail')
|
2014-11-30 06:13:37 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
|
|
|
@response[:message] = I18n.t('messages.friend.create.okay')
|
|
|
|
@response[:success] = true
|
2014-11-30 05:45:32 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2014-11-30 06:13:37 -08:00
|
|
|
params.require :screen_name
|
|
|
|
|
|
|
|
target_user = User.find_by_screen_name(params[:screen_name])
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.unfollow target_user
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue => e
|
|
|
|
NewRelic::Agent.notice_error(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :fail
|
|
|
|
@response[:message] = I18n.t('messages.friend.destroy.fail')
|
2014-11-30 06:13:37 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
|
|
|
@response[:message] = I18n.t('messages.friend.destroy.okay')
|
|
|
|
@response[:success] = true
|
2014-11-30 05:45:32 -08:00
|
|
|
end
|
|
|
|
end
|