新增:项目标记关联组织接口

This commit is contained in:
2024-01-04 14:25:40 +08:00
parent 7d1b4da72c
commit 5fafd8195c
4 changed files with 78 additions and 1 deletions

View File

@@ -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