Retrospring/app/controllers/relationships_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.5 KiB
Ruby
Raw Normal View History

2023-10-25 23:16:18 -07:00
# frozen_string_literal: true
class RelationshipsController < ApplicationController
include TurboStreamable
before_action :authenticate_user!
turbo_stream_actions :create, :destroy
def create
params.require :screen_name
2023-10-25 23:16:18 -07:00
UseCase::Relationship::Create.call(
source_user: current_user,
target_user: ::User.find_by!(screen_name: params[:screen_name]),
2023-10-26 13:15:51 -07:00
type: params[:type],
2023-10-25 23:16:18 -07:00
)
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]),
2023-10-26 13:15:51 -07:00
type: params[:type],
2023-10-25 23:16:18 -07:00
)
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