50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class RelationshipsController < ApplicationController
|
|
include TurboStreamable
|
|
|
|
before_action :authenticate_user!
|
|
|
|
turbo_stream_actions :create, :destroy
|
|
|
|
def create
|
|
params.require :screen_name
|
|
|
|
UseCase::Relationship::Create.call(
|
|
source_user: current_user,
|
|
target_user: ::User.find_by!(screen_name: params[:screen_name]),
|
|
type: params[:type],
|
|
)
|
|
|
|
respond_to do |format|
|
|
format.turbo_stream do
|
|
render turbo_stream: [
|
|
turbo_stream.replace("#{params[:type]}-#{params[:screen_name]}", partial: "relationships/destroy", locals: { type: params[:type], screen_name: params[:screen_name] }),
|
|
render_toast(t(".#{params[:type]}.success"))
|
|
]
|
|
end
|
|
|
|
format.html { redirect_back(fallback_location: user_path(username: params[:screen_name])) }
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
UseCase::Relationship::Destroy.call(
|
|
source_user: current_user,
|
|
target_user: ::User.find_by!(screen_name: params[:screen_name]),
|
|
type: params[:type],
|
|
)
|
|
|
|
respond_to do |format|
|
|
format.turbo_stream do
|
|
render turbo_stream: [
|
|
turbo_stream.replace("#{params[:type]}-#{params[:screen_name]}", partial: "relationships/create", locals: { type: params[:type], screen_name: params[:screen_name] }),
|
|
render_toast(t(".#{params[:type]}.success"))
|
|
]
|
|
end
|
|
|
|
format.html { redirect_back(fallback_location: user_path(username: params[:screen_name])) }
|
|
end
|
|
end
|
|
end
|