1
0
Fork 0

REFACTOR: use NewPostManager instead of PostCreator

Dieser Commit ist enthalten in:
Faizaan Gagan 2020-12-03 20:15:10 +05:30
Ursprung 39ce7248a8
Commit c6ab9f84bf

Datei anzeigen

@ -20,10 +20,6 @@ class CustomWizard::Action
self.send(action['type'].to_sym) self.send(action['type'].to_sym)
end end
if creates_post? && @result.success?
@result.handler.enqueue_jobs
end
if @result.success? && @result.output.present? if @result.success? && @result.output.present?
data[action['id']] = @result.output data[action['id']] = @result.output
end end
@ -39,20 +35,20 @@ class CustomWizard::Action
params = basic_topic_params.merge(public_topic_params) params = basic_topic_params.merge(public_topic_params)
if params[:title].present? && params[:raw].present? if params[:title].present? && params[:raw].present?
creator = PostCreator.new(user, params) manager = NewPostManager.new(user, params)
post = creator.create post_result = manager.perform
if creator.errors.present? if post_result.errors.present?
messages = creator.errors.full_messages.join(" ") messages = post_result.errors.full_messages.join(" ")
log_error("failed to create", messages) log_error("failed to create", messages)
elsif action['skip_redirect'].blank? elsif action['skip_redirect'].blank?
data['redirect_on_complete'] = post.topic.url data['redirect_on_complete'] = post_result.post.topic.url
end end
if creator.errors.blank? if post_result.errors.blank?
log_success("created topic", "id: #{post.topic.id}") log_success("created topic", "id: #{post_result.post.topic.id}")
result.handler = creator result.handler = manager
result.output = post.topic.id result.output = post_result.post.topic.id
end end
else else
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}") log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
@ -105,20 +101,20 @@ class CustomWizard::Action
params[:archetype] = Archetype.private_message params[:archetype] = Archetype.private_message
creator = PostCreator.new(user, params) manager = NewPostManager.new(user, params)
post = creator.create post_result = manager.perform
if creator.errors.present? if post_result.errors.present?
messages = creator.errors.full_messages.join(" ") messages = post_result.errors.full_messages.join(" ")
log_error("failed to create message", messages) log_error("failed to create message", messages)
elsif action['skip_redirect'].blank? elsif action['skip_redirect'].blank?
data['redirect_on_complete'] = post.topic.url data['redirect_on_complete'] = post_result.post.topic.url
end end
if creator.errors.blank? if post_result.errors.blank?
log_success("created message", "id: #{post.topic.id}") log_success("created message", "id: #{post_result.post.topic.id}")
result.handler = creator result.handler = manager
result.output = post.topic.id result.output = post_result.post.topic.id
end end
else else
log_error( log_error(