42 lines
1.3 KiB
Ruby
42 lines
1.3 KiB
Ruby
class Api::Pm::ProjectsController < Api::Pm::BaseController
|
|
before_action :require_login, except: [:convert]
|
|
before_action :load_project, only: [:convert]
|
|
def convert
|
|
data = {
|
|
owner: @project.owner.try(:login),
|
|
identifier: @project.identifier
|
|
}
|
|
render_ok(data: data)
|
|
end
|
|
|
|
def issues_count
|
|
return tip_exception '参数错误' unless params[:pm_project_id].present?
|
|
@issues = Issue.where(pm_project_id: params[:pm_project_id])
|
|
data = {}
|
|
@issues_count = @issues.group(:pm_project_id).count
|
|
# requirement 1 task 2 bug 3
|
|
@issues_type_count = @issues.group(:pm_project_id, :pm_issue_type).count
|
|
params[:pm_project_id].map(&:to_i).map do |project_id|
|
|
data[project_id] = {
|
|
total: @issues_count[project_id] || 0,
|
|
requirement: @issues_type_count[[project_id, 1]] || 0,
|
|
task: @issues_type_count[[project_id, 2]] || 0,
|
|
bug: @issues_type_count[[project_id, 3]] || 0
|
|
}
|
|
end
|
|
render_ok(data: data)
|
|
end
|
|
|
|
def bind_project
|
|
return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin?
|
|
Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id])
|
|
end
|
|
|
|
private
|
|
def load_project
|
|
@project = Project.joins(:owner).find params[:project_id]
|
|
end
|
|
|
|
|
|
end
|