add blockchain operation after comments

This commit is contained in:
nigel007 2021-01-03 17:09:19 +08:00
parent f4f1aef365
commit cbb666052c
1 changed files with 35 additions and 23 deletions

View File

@ -21,32 +21,44 @@ class JournalsController < ApplicationController
if notes.blank?
normal_status(-1, "评论内容不能为空")
else
journal_params = {
journalized_id: @issue.id ,
journalized_type: "Issue",
user_id: current_user.id ,
notes: notes.to_s.strip,
parent_id: params[:parent_id]
}
journal = Journal.new journal_params
if journal.save
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = journal
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
ActiveRecord::Base.transaction do
journal_params = {
journalized_id: @issue.id ,
journalized_type: "Issue",
user_id: current_user.id ,
notes: notes.to_s.strip,
parent_id: params[:parent_id]
}
journal = Journal.new journal_params
if journal.save
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = journal
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end
end
end
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
render :json => { status: 0, message: "评论成功", id: journal.id}
# normal_status(0, "评论成功")
else
normal_status(-1, "评论失败")
# author: zxh
# 调用上链API
success_blockchain = push_activity_2_blockchain("issue_comment_create", journal)
if success_blockchain == false
normal_status(-1, "评论失败")
raise ActiveRecord::Rollback
else
render json: {status: 0, message: "评论成功", id: journal.id}
end
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
# normal_status(0, "评论成功")
else
normal_status(-1, "评论失败")
raise ActiveRecord::Rollback
end
end
end
end