add: project trace tasks count
This commit is contained in:
parent
1f13bba52e
commit
7750cbe272
|
@ -5,13 +5,13 @@ class Traces::ProjectsController < Traces::BaseController
|
|||
|
||||
def tasks
|
||||
branch_name = params[:branch_name]
|
||||
return render_error("无可用检测次数") if current_user.trace_user&.tasks_count >= 5
|
||||
return render_error("无可用检测次数") if @project&.trace_tasks_count >= 5
|
||||
return render_error("分支名不能为空!") if branch_name.blank?
|
||||
@all_branches = Gitea::Repository::Branches::ListNameService.call(@project&.owner, @project.identifier)
|
||||
return render_error("请输入正确的分支名!") unless @all_branches["branch_name"].include?(branch_name)
|
||||
code, data, error = Trace::CheckService.call(current_user.trace_token, @project, "1", branch_name)
|
||||
if code == 200
|
||||
current_user.trace_user.increment!(:tasks_count, 1)
|
||||
@project.increment!(:trace_tasks_count, 1)
|
||||
render_ok
|
||||
else
|
||||
render_error("检测失败 Error:#{error}")
|
||||
|
@ -27,7 +27,7 @@ class Traces::ProjectsController < Traces::BaseController
|
|||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
code, data, error = Trace::CheckResultService.call(current_user.trace_token, @project, nil, page, limit)
|
||||
if code == 200
|
||||
current_user.trace_user.update_column(:tasks_count, data[0]["totalsize"]) if data.size > 0
|
||||
@project.update_column(:trace_tasks_count, data[0]["totalsize"]) if data.size > 0
|
||||
render :json => {data: data}
|
||||
else
|
||||
render_error("获取检测记录失败 Error:#{error}")
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
#
|
||||
# Table name: trace_users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# username :string(255)
|
||||
# password :string(255)
|
||||
# unit :string(255)
|
||||
# telnumber :string(255)
|
||||
# email :string(255)
|
||||
# name :string(255)
|
||||
# token :text(65535)
|
||||
# expired_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# tasks_count :integer default("0")
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# username :string(255)
|
||||
# password :string(255)
|
||||
# unit :string(255)
|
||||
# telnumber :string(255)
|
||||
# email :string(255)
|
||||
# name :string(255)
|
||||
# token :text(65535)
|
||||
# expired_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
class AddTasksCountToTraceUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :trace_users, :tasks_count, :integer, default: 0
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddTraceTasksCountToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :projects, :trace_tasks_count, :integer, default: 0
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue