新增:项目标记关联组织接口
This commit is contained in:
parent
7d1b4da72c
commit
5fafd8195c
|
@ -0,0 +1,67 @@
|
||||||
|
class Api::Pm::IssueTagsController < Api::Pm::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@issue_tags = IssueTag.pm_able
|
||||||
|
@issue_tags = @issue_tags.where(organization_id: params[:organization_id]) if params[:organization_id].present?
|
||||||
|
@issue_tags = @issue_tags.where(pm_project_id: params[:pm_project_id]) if params[:pm_project_id].present?
|
||||||
|
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||||
|
@issue_tags = @issue_tags.reorder("#{tag_sort_by} #{tag_sort_direction}")
|
||||||
|
@issue_tags = kaminari_paginate(@issue_tags)
|
||||||
|
render "api/v1/issues/issue_tags/index"
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
return render_error("请输入正确的OrganizationID") unless Organization.exists?(id: issue_tag_create_params[:organization_id])
|
||||||
|
@issue_tag = IssueTag.new(issue_tag_create_params.merge!(project_id: 0))
|
||||||
|
if @issue_tag.save!
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("创建标记失败!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
before_action :load_issue_tag, only: [:update, :destroy]
|
||||||
|
|
||||||
|
def update
|
||||||
|
@issue_tag.attributes = issue_tag_update_params
|
||||||
|
if @issue_tag.save!
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("更新标记失败!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @issue_tag.destroy!
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("删除标记失败!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def tag_sort_by
|
||||||
|
sort_by = params.fetch(:sort_by, "created_at")
|
||||||
|
sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at"
|
||||||
|
sort_by
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag_sort_direction
|
||||||
|
sort_direction = params.fetch(:sort_direction, "desc").downcase
|
||||||
|
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
|
||||||
|
sort_direction
|
||||||
|
end
|
||||||
|
|
||||||
|
def issue_tag_create_params
|
||||||
|
params.permit(:name, :description, :color, :pm_project_id, :organization_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def issue_tag_update_params
|
||||||
|
params.permit(:name, :description, :color)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_issue_tag
|
||||||
|
@issue_tag = IssueTag.pm_able.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
end
|
|
@ -15,9 +15,11 @@
|
||||||
# gitea_url :string(255)
|
# gitea_url :string(255)
|
||||||
# pull_requests_count :integer default("0")
|
# pull_requests_count :integer default("0")
|
||||||
# pm_project_id :integer
|
# pm_project_id :integer
|
||||||
|
# organization_id :integer
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
# index_issue_tags_on_organization_id (organization_id)
|
||||||
# index_issue_tags_on_user_id_and_name_and_project_id (user_id,name,project_id)
|
# index_issue_tags_on_user_id_and_name_and_project_id (user_id,name,project_id)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -29,6 +31,9 @@ class IssueTag < ApplicationRecord
|
||||||
has_many :pull_request_issues, -> {where(issue_classify: "pull_request")}, source: :issue, through: :issue_tags_relates
|
has_many :pull_request_issues, -> {where(issue_classify: "pull_request")}, source: :issue, through: :issue_tags_relates
|
||||||
belongs_to :project, optional: true, counter_cache: true
|
belongs_to :project, optional: true, counter_cache: true
|
||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
|
belongs_to :organization, optional: true
|
||||||
|
|
||||||
|
scope :pm_able, -> {where(project_id: 0)}
|
||||||
|
|
||||||
validates :name, uniqueness: {scope: :project_id, message: "已存在" }, if: :pm_project?
|
validates :name, uniqueness: {scope: :project_id, message: "已存在" }, if: :pm_project?
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ defaults format: :json do
|
||||||
get :link_index
|
get :link_index
|
||||||
get :parent_issues
|
get :parent_issues
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :issue_links
|
resources :issue_links
|
||||||
|
|
||||||
resources :journals do
|
resources :journals do
|
||||||
|
@ -22,6 +21,7 @@ defaults format: :json do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :issue_tags
|
||||||
resources :sprint_issues, only: [:index] do
|
resources :sprint_issues, only: [:index] do
|
||||||
collection do
|
collection do
|
||||||
get :statistics
|
get :statistics
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddOrganizationIdToIssueTags < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_reference :issue_tags, :organization
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue