From 8f98a833793050d2e26515991c13fd85ff5d30a4 Mon Sep 17 00:00:00 2001 From: "vilet.yy" Date: Wed, 17 Mar 2021 13:50:26 +0800 Subject: [PATCH] add: project unit list --- .../projects/project_units_controller.rb | 4 ++ app/docs/slate/source/includes/_projects.md | 42 ++++++++++++++++++- .../project_units/index.json.jbuilder | 3 ++ config/routes.rb | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/views/projects/project_units/index.json.jbuilder diff --git a/app/controllers/projects/project_units_controller.rb b/app/controllers/projects/project_units_controller.rb index ddb90fce2..90bc64a71 100644 --- a/app/controllers/projects/project_units_controller.rb +++ b/app/controllers/projects/project_units_controller.rb @@ -1,4 +1,8 @@ class Projects::ProjectUnitsController < Projects::BaseController + def index + @project_units = @project.project_units + end + def create if current_user.admin? || @project.owner?(current_user) ActiveRecord::Base.transaction do diff --git a/app/docs/slate/source/includes/_projects.md b/app/docs/slate/source/includes/_projects.md index 0e2fc13fd..0a46d8cc7 100644 --- a/app/docs/slate/source/includes/_projects.md +++ b/app/docs/slate/source/includes/_projects.md @@ -261,8 +261,46 @@ attachments |array|附件 Remember — a happy kitten is an authenticated kitten! -## 更改项目导航 -更改项目导航信息 +## 项目模块信息 +项目模块信息 + +> 示例: + +```shell +curl -X GET \ +http://localhost:3000/api/yystopf/ceshi/project_units.json +``` + +```javascript +await octokit.request('GET /api/yystopf/ceshi/project_units') +``` + +### HTTP 请求 +`GET /api/yystopf/ceshi/project_units` + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|type |string|模块名称 | + +> 返回的JSON示例: + +```json +[ + { + "type": "code" + }, + { + "type": "pulls" + }, + { + "type": "issues" + } +] +``` + +## 更改项目模块展示 +更改项目模块展示 > 示例: diff --git a/app/views/projects/project_units/index.json.jbuilder b/app/views/projects/project_units/index.json.jbuilder new file mode 100644 index 000000000..e88393876 --- /dev/null +++ b/app/views/projects/project_units/index.json.jbuilder @@ -0,0 +1,3 @@ +json.array! @project_units do |unit| + json.type unit.unit_type +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 27af236a5..fd3b22ec9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -529,7 +529,7 @@ Rails.application.routes.draw do scope module: :projects do resources :teams, only: [:index, :create, :destroy] - resources :project_units, only: [:create] + resources :project_units, only: [:index, :create] scope do get( '/blob/*id/diff',