2022-01-02 15:31:55 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Ajax::RelationshipController < AjaxController
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
def create
|
2022-01-19 10:24:54 -08:00
|
|
|
params.require :screen_name
|
2022-01-16 09:38:06 -08:00
|
|
|
|
2022-01-02 15:31:55 -08:00
|
|
|
UseCase::Relationship::Create.call(
|
2022-01-22 14:37:51 -08:00
|
|
|
source_user: current_user,
|
2022-06-11 14:10:20 -07:00
|
|
|
target_user: ::User.find_by!(screen_name: params[:screen_name]),
|
2022-01-22 13:48:55 -08:00
|
|
|
type: params[:type]
|
2022-01-02 15:31:55 -08:00
|
|
|
)
|
|
|
|
@response[:success] = true
|
2022-07-06 00:21:15 -07:00
|
|
|
@response[:message] = t(".#{params[:type]}.success")
|
2022-01-19 10:57:51 -08:00
|
|
|
rescue Errors::Base => e
|
|
|
|
@response[:message] = t(e.locale_tag)
|
2022-01-02 15:31:55 -08:00
|
|
|
ensure
|
|
|
|
return_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
UseCase::Relationship::Destroy.call(
|
2022-01-22 14:37:51 -08:00
|
|
|
source_user: current_user,
|
2022-06-11 14:10:20 -07:00
|
|
|
target_user: ::User.find_by!(screen_name: params[:screen_name]),
|
2022-01-22 13:48:55 -08:00
|
|
|
type: params[:type]
|
2022-01-02 15:31:55 -08:00
|
|
|
)
|
|
|
|
@response[:success] = true
|
2022-07-06 00:21:15 -07:00
|
|
|
@response[:message] = t(".#{params[:type]}.success")
|
2022-01-19 10:57:51 -08:00
|
|
|
rescue Errors::Base => e
|
|
|
|
@response[:message] = t(e.locale_tag)
|
2022-01-02 15:31:55 -08:00
|
|
|
ensure
|
|
|
|
return_response
|
|
|
|
end
|
|
|
|
end
|