gitlink-forgeplus/app/controllers/api/pm/issues_controller.rb

80 lines
2.6 KiB
Ruby

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