add: trace user tasks_count

This commit is contained in:
yystopf 2022-05-11 10:34:35 +08:00
parent 5dcee1b4dc
commit 1f13bba52e
3 changed files with 21 additions and 12 deletions

View File

@ -5,11 +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 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)
render_ok
else
render_error("检测失败 Error:#{error}")
@ -25,6 +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
render :json => {data: data}
else
render_error("获取检测记录失败 Error:#{error}")

View File

@ -2,18 +2,19 @@
#
# 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
# 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")
#
# Indexes
#

View File

@ -0,0 +1,5 @@
class AddTasksCountToTraceUsers < ActiveRecord::Migration[5.2]
def change
add_column :trace_users, :tasks_count, :integer, default: 0
end
end