2022-06-12 04:46:48 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
class Ajax::QuestionController < AjaxController
|
2015-04-25 18:36:25 -07:00
|
|
|
def destroy
|
|
|
|
params.require :question
|
|
|
|
|
2022-07-07 09:38:04 -07:00
|
|
|
UseCase::Question::Destroy.call(
|
|
|
|
question_id: params[:question],
|
|
|
|
current_user: current_user
|
|
|
|
)
|
2015-04-25 18:36:25 -07:00
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
2022-07-06 02:23:54 -07:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:success] = true
|
2015-04-25 18:36:25 -07:00
|
|
|
end
|
|
|
|
|
2014-11-10 12:56:30 -08:00
|
|
|
def create
|
|
|
|
params.require :question
|
|
|
|
params.require :anonymousQuestion
|
|
|
|
params.require :rcpt
|
|
|
|
|
2022-01-23 10:25:56 -08:00
|
|
|
# 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"),
|
|
|
|
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-02-06 22:38:59 -08:00
|
|
|
author_identifier: AnonymousBlock.get_identifier(request.remote_ip)
|
2022-01-23 10:25:56 -08:00
|
|
|
)
|
2020-04-30 13:49:15 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-01-23 10:25:56 -08:00
|
|
|
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-02-04 13:31:53 -08:00
|
|
|
author_identifier: AnonymousBlock.get_identifier(request.remote_ip)
|
2022-01-23 10:25:56 -08:00
|
|
|
)
|
2015-04-18 15:17:13 -07:00
|
|
|
end
|
2014-11-10 12:56:30 -08:00
|
|
|
end
|