diff --git a/app/assets/javascripts/api/v1/pm_issues.js b/app/assets/javascripts/api/v1/pm_issues.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/v1/pm_issues.js @@ -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. diff --git a/app/assets/stylesheets/api/v1/pm_issues.scss b/app/assets/stylesheets/api/v1/pm_issues.scss new file mode 100644 index 000000000..92defb491 --- /dev/null +++ b/app/assets/stylesheets/api/v1/pm_issues.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/v1/pm_issues controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/v1/pm_issues_controller.rb b/app/controllers/api/v1/pm_issues_controller.rb new file mode 100644 index 000000000..5c2e0f987 --- /dev/null +++ b/app/controllers/api/v1/pm_issues_controller.rb @@ -0,0 +1,36 @@ +class Api::V1::PmIssuesController < ApplicationController + before_action :require_login, except: [:index, :show] + + 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, + :issue_tag_ids => [], + :assigner_ids => [], + :attachment_ids => [], + :receivers_login => [] + ) + end + +end diff --git a/app/helpers/api/v1/pm_issues_helper.rb b/app/helpers/api/v1/pm_issues_helper.rb new file mode 100644 index 000000000..ced4b55c9 --- /dev/null +++ b/app/helpers/api/v1/pm_issues_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::PmIssuesHelper +end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index c155b69d4..fc81f4dde 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -29,6 +29,8 @@ class Api::V1::Issues::CreateService < ApplicationService @assigner_ids = params[:assigner_ids] @attachment_ids = params[:attachment_ids] @receivers_login = params[:receivers_login] + @pm_project_id = params[:pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] end def call @@ -57,7 +59,8 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.assigners = @assigners unless assigner_ids.blank? @created_issue.attachments = @attachments unless attachment_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? - + @created_issue.pm_project_id = @pm_project_id + @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! @@ -135,6 +138,7 @@ class Api::V1::Issues::CreateService < ApplicationService end def build_issue_project_trends + return if @project.id == 0 @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"}) @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5 end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index b6ef11789..862524bf3 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,6 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user + attr_reader :pm_project_id, :pm_sprint_id attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} @@ -26,6 +27,8 @@ class Api::V1::Issues::ListService < ApplicationService @begin_date = params[:begin_date] @end_date = params[:end_date] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' + @pm_project_id = params[:pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end @@ -65,6 +68,12 @@ class Api::V1::Issues::ListService < ApplicationService # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? + # pm_project_id + issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present? + + # pm_sprint_id + issues = issues.where(pm_sprint_id: pm_sprint_id) if pm_sprint_id.present? + # assigner_id issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present? diff --git a/app/views/api/v1/pm_issues/create.json.jbuilder b/app/views/api/v1/pm_issues/create.json.jbuilder new file mode 100644 index 000000000..f45ef5b2f --- /dev/null +++ b/app/views/api/v1/pm_issues/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/issues/detail", locals: {issue: @object_result} diff --git a/config/routes/api.rb b/config/routes/api.rb index 41d331168..5b1f37d8d 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -44,6 +44,7 @@ defaults format: :json do collection do patch :batch_update delete :batch_destroy + post :pm_create end member do @@ -54,12 +55,15 @@ defaults format: :json do end end end + + resources :pm_issues + scope module: :issues do resources :issue_tags, except: [:new, :edit] do - collection do - get :pm_index + collection do + get :pm_index + end end - end resources :milestones, except: [:new, :edit] resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do collection do diff --git a/spec/controllers/api/v1/pm_issues_controller_spec.rb b/spec/controllers/api/v1/pm_issues_controller_spec.rb new file mode 100644 index 000000000..f68abf45f --- /dev/null +++ b/spec/controllers/api/v1/pm_issues_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::PmIssuesController, type: :controller do + +end diff --git a/spec/helpers/api/v1/pm_issues_helper_spec.rb b/spec/helpers/api/v1/pm_issues_helper_spec.rb new file mode 100644 index 000000000..4b67710fb --- /dev/null +++ b/spec/helpers/api/v1/pm_issues_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::V1::PmIssuesHelper. For example: +# +# describe Api::V1::PmIssuesHelper 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 Api::V1::PmIssuesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end