Browse Source

根据pm管理需求新增issue接口

pull/347/head
呱呱呱 2 years ago
parent
commit
f6ffaa82a6
9 changed files with 63 additions and 4 deletions
  1. +2
    -0
      app/assets/javascripts/api/v1/pm_issues.js
  2. +3
    -0
      app/assets/stylesheets/api/v1/pm_issues.scss
  3. +23
    -0
      app/controllers/api/v1/pm_issues_controller.rb
  4. +2
    -0
      app/helpers/api/v1/pm_issues_helper.rb
  5. +5
    -1
      app/services/api/v1/issues/create_service.rb
  6. +1
    -0
      app/views/api/v1/pm_issues/create.json.jbuilder
  7. +7
    -3
      config/routes/api.rb
  8. +5
    -0
      spec/controllers/api/v1/pm_issues_controller_spec.rb
  9. +15
    -0
      spec/helpers/api/v1/pm_issues_helper_spec.rb

+ 2
- 0
app/assets/javascripts/api/v1/pm_issues.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.

+ 3
- 0
app/assets/stylesheets/api/v1/pm_issues.scss View File

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

+ 23
- 0
app/controllers/api/v1/pm_issues_controller.rb View File

@@ -0,0 +1,23 @@
class Api::V1::PmIssuesController < ApplicationController
before_action :require_login, except: [:index, :show]

def create
project = Project.new( id: 0, user_id: current_user.id, 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

+ 2
- 0
app/helpers/api/v1/pm_issues_helper.rb View File

@@ -0,0 +1,2 @@
module Api::V1::PmIssuesHelper
end

+ 5
- 1
app/services/api/v1/issues/create_service.rb View File

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


+ 1
- 0
app/views/api/v1/pm_issues/create.json.jbuilder View File

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

+ 7
- 3
config/routes/api.rb View File

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


+ 5
- 0
spec/controllers/api/v1/pm_issues_controller_spec.rb View File

@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Api::V1::PmIssuesController, type: :controller do

end

+ 15
- 0
spec/helpers/api/v1/pm_issues_helper_spec.rb View File

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

Loading…
Cancel
Save