Merge pull request '调整Pm Issue相关接口' (#169) from KingChan/forgeplus:pm_project_develop into pm_project_develop

This commit is contained in:
KingChan 2023-11-01 10:47:32 +08:00
commit 41bdbd9531
22 changed files with 210 additions and 10 deletions

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,3 @@
// Place all the styles related to the pm/issues controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the pm/journals controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,79 @@
class Api::Pm::IssuesController < ApplicationController
before_action :require_login, except: [:index]
before_action :load_issue, only: [:show, :children, :update, :destroy]
def index
@project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm')
@object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
@total_issues_count = @object_result[:total_issues_count]
@opened_issues_count = @object_result[:opened_issues_count]
@closed_issues_count = @object_result[:closed_issues_count]
if params[:only_name].present?
@issues = kaminary_select_paginate(
@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
else
@issues = kaminari_paginate(@object_result[:data])
end
render "api/v1/issues/index"
end
def show
@issue.associate_attachment_container
render "api/v1/issues/show"
end
def create
project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm')
@object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user)
render "api/v1/issues/create"
end
def update
@object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
end
def destroy
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
if @object_result
render_ok
else
render_error('删除疑修失败!')
end
end
private
def load_issue
@project = Project.new(id: params[:project_id], user_id: 0, name: 'pm_mm', identifier: 'pm_mm')
@issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id], pm_sprint_id:params[:pm_sprint_id]).find_by_id(params[:id])
if @issue.blank?
render_not_found("疑修不存在!")
end
end
def query_params
params.permit(
:only_name,
:category,
:participant_category,
:keyword, :author_id,
:milestone_id, :assigner_id,
:status_id,
:begin_date, :end_date,
:sort_by, :sort_direction,:parent_id,
:issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type
)
end
def issue_params
params.permit(
:status_id, :priority_id, :milestone_id,
:branch_name, :start_date, :due_date,
:subject, :description, :blockchain_token_num,
:pm_project_id, :pm_sprint_id, :pm_issue_type, :parent_id,
issue_tag_ids: [],
assigner_ids: [],
attachment_ids: [],
receivers_login: []
)
end
end

View File

@ -0,0 +1,37 @@
class Pm::IssuesController < ApplicationController
before_action :require_login, except: [:index]
def index
@project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm')
@object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
@total_issues_count = @object_result[:total_issues_count]
@opened_issues_count = @object_result[:opened_issues_count]
@closed_issues_count = @object_result[:closed_issues_count]
if params[:only_name].present?
@issues = kaminary_select_paginate(
@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
else
@issues = kaminari_paginate(@object_result[:data])
end
end
def create
project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm')
@object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user)
end
private
def issue_params
params.permit(
:status_id, :priority_id, :milestone_id,
:branch_name, :start_date, :due_date,
:subject, :description, :blockchain_token_num,
:pm_project_id, :pm_sprint_id, :pm_issue_type,
issue_tag_ids: [],
assigner_ids: [],
attachment_ids: [],
receivers_login: []
)
end
end

View File

@ -0,0 +1,2 @@
module Pm::IssuesHelper
end

View File

@ -0,0 +1,2 @@
module Pm::JournalsHelper
end

View File

@ -36,6 +36,7 @@
# blockchain_token_num :integer # blockchain_token_num :integer
# pm_project_id :integer # pm_project_id :integer
# pm_sprint_id :integer # pm_sprint_id :integer
# pm_issue_type :integer
# #
# Indexes # Indexes
# #

View File

@ -47,6 +47,7 @@ module Api::V1::Issues::Concerns::Checkable
end end
def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0) def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0)
return if project_id.zero?
left_blockchain_token_num = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id}) rescue 0 left_blockchain_token_num = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id}) rescue 0
raise ApplicationService::Error, "用户Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i raise ApplicationService::Error, "用户Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i
end end

View File

@ -31,9 +31,11 @@ class Api::V1::Issues::CreateService < ApplicationService
@receivers_login = params[:receivers_login] @receivers_login = params[:receivers_login]
@pm_project_id = params[:pm_project_id] @pm_project_id = params[:pm_project_id]
@pm_sprint_id = params[:pm_sprint_id] @pm_sprint_id = params[:pm_sprint_id]
@pm_issue_type = params[:pm_issue_type]
@parent_id = params[:parent_id]
end end
def call def call
raise Error, errors.full_messages.join(", ") unless valid? raise Error, errors.full_messages.join(", ") unless valid?
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
check_issue_status(status_id) check_issue_status(status_id)
@ -48,7 +50,6 @@ class Api::V1::Issues::CreateService < ApplicationService
load_attachments(attachment_ids) unless attachment_ids.blank? load_attachments(attachment_ids) unless attachment_ids.blank?
load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
load_atme_receivers(receivers_login) unless receivers_login.blank? load_atme_receivers(receivers_login) unless receivers_login.blank?
try_lock("Api::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁 try_lock("Api::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁
@created_issue = Issue.new(issue_attributes) @created_issue = Issue.new(issue_attributes)
build_author_participants build_author_participants
@ -61,6 +62,8 @@ class Api::V1::Issues::CreateService < ApplicationService
@created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank?
@created_issue.pm_project_id = @pm_project_id @created_issue.pm_project_id = @pm_project_id
@created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_sprint_id = @pm_sprint_id
@created_issue.pm_issue_type = @pm_issue_type
@created_issue.parent_id = @parent_id
@created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank?
@created_issue.save! @created_issue.save!

View File

@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService
attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids
attr_reader :begin_date, :end_date attr_reader :begin_date, :end_date
attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user
attr_reader :pm_project_id, :pm_sprint_id attr_reader :pm_project_id, :pm_sprint_id, :parent_id, :pm_issue_type
attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count
validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"}
@ -29,6 +29,8 @@ class Api::V1::Issues::ListService < ApplicationService
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on'
@pm_project_id = params[:pm_project_id] @pm_project_id = params[:pm_project_id]
@pm_sprint_id = params[:pm_sprint_id] @pm_sprint_id = params[:pm_sprint_id]
@parent_id = params[:parent_id]
@pm_issue_type = params[:pm_issue_type]
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase
@current_user = current_user @current_user = current_user
end end
@ -64,10 +66,17 @@ class Api::V1::Issues::ListService < ApplicationService
# issue_tag_ids # issue_tag_ids
issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank? issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank?
# milestone_id # milestone_id
issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present?
#pm相关
# parent_id,
issues = issues.where(parent_id: parent_id) if parent_id.present?
# pm_issue_type
issues = issues.where(pm_issue_type: pm_issue_type) if pm_issue_type.present?
# pm_project_id # pm_project_id
issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present? issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present?

View File

@ -44,4 +44,8 @@ json.operate_journals_count issue.operate_journals.size
json.attachments issue.attachments.each do |attachment| json.attachments issue.attachments.each do |attachment|
json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment}
end end
json.pull_fixed issue.pull_attached_issues.where(fixed: true).present? json.pull_fixed issue.pull_attached_issues.where(fixed: true).present?
json.parent_id issue.parent_id
json.pm_issue_type issue.pm_issue_type
json.pm_sprint_id issue.pm_sprint_id
json.pm_project_id issue.pm_project_id

View File

@ -7,6 +7,6 @@ json.issues @issues.each do |issue|
if params[:only_name].present? if params[:only_name].present?
json.(issue, :id, :subject, :project_issues_index) json.(issue, :id, :subject, :project_issues_index)
else else
json.partial! "simple_detail", locals: {issue: issue} json.partial! "api/v1/issues/simple_detail", locals: {issue: issue}
end end
end end

View File

@ -1 +0,0 @@
json.partial! "api/v1/issues/detail", locals: {issue: @object_result}

View File

@ -792,6 +792,11 @@ Rails.application.routes.draw do
end end
end end
namespace :pm do
resource :issues
resource :journals
end
namespace :admins do namespace :admins do
mount Sidekiq::Web => '/sidekiq' mount Sidekiq::Web => '/sidekiq'
get '/', to: 'dashboards#index' get '/', to: 'dashboards#index'

View File

@ -1,5 +1,9 @@
defaults format: :json do defaults format: :json do
namespace :api do namespace :api do
namespace :pm do
resources :issues
end
namespace :v1 do namespace :v1 do
resources :users, only: [:index] do resources :users, only: [:index] do
@ -56,8 +60,7 @@ defaults format: :json do
end end
end end
resources :pm_issues
scope module: :issues do scope module: :issues do
resources :issue_tags, except: [:new, :edit] do resources :issue_tags, except: [:new, :edit] do
collection do collection do

View File

@ -0,0 +1,5 @@
class AddPmIssueTypeToIssues < ActiveRecord::Migration[5.2]
def change
add_column :issues, :pm_issue_type, :integer
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Pm::IssuesController, type: :controller do
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Pm::JournalsController, type: :controller do
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Pm::IssuesHelper. For example:
#
# describe Pm::IssuesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Pm::IssuesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Pm::JournalsHelper. For example:
#
# describe Pm::JournalsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Pm::JournalsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end