Retrospring/app/controllers/ajax/question_controller.rb

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

49 lines
1.3 KiB
Ruby
Raw Normal View History

2022-06-12 04:46:48 -07:00
# frozen_string_literal: true
class Ajax::QuestionController < AjaxController
def create
params.require :question
params.require :anonymousQuestion
params.require :rcpt
# set up fake success response -- the use cases raise errors on exceptions
# which get rescued by the base class
@response = {
success: true,
message: t(".success"),
2023-12-11 10:56:50 -08:00
status: :okay,
}
if user_signed_in? && params[:rcpt] == "followers"
UseCase::Question::CreateFollowers.call(
2022-01-24 13:46:11 -08:00
source_user_id: current_user.id,
content: params[:question],
2023-12-11 10:56:50 -08:00
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
send_to_own_inbox: params[:sendToOwnInbox],
)
return
end
UseCase::Question::Create.call(
2022-01-24 13:46:11 -08:00
source_user_id: user_signed_in? ? current_user.id : nil,
target_user_id: params[:rcpt],
content: params[:question],
anonymous: params[:anonymousQuestion],
2023-12-11 10:56:50 -08:00
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
)
end
2023-12-11 10:56:50 -08:00
def destroy
params.require :question
UseCase::Question::Destroy.call(
question_id: params[:question],
2023-12-11 10:59:07 -08:00
current_user:,
2023-12-11 10:56:50 -08:00
)
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
end