Browse Source

Merge branch 'dev_trustie' into dev_devops

tags/v1.0.0
Jasder 5 years ago
parent
commit
b8cace558b
7 changed files with 135 additions and 0 deletions
  1. +85
    -0
      README.md
  2. +27
    -0
      app/controllers/projects_controller.rb
  3. +1
    -0
      app/models/project.rb
  4. +4
    -0
      app/models/project_detail.rb
  5. +5
    -0
      app/views/projects/about.json.jbuilder
  6. +1
    -0
      config/routes.rb
  7. +12
    -0
      db/migrate/20201004070431_create_project_details.rb

+ 85
- 0
README.md View File

@@ -1422,6 +1422,91 @@ http://localhost:3000/api/projects/recommend | jq
```
---

#### 项目主页
```
GET api/:namespace_id/:id/about
```

*示例*
```
curl -X GET \
http://localhost:3000/api/:jason/forgeplus/about | jq
```

*请求参数说明:*

|参数名|必选|类型|说明|
|-|-|-|-|
|namespace_id |是|string |用户登录名 |
|id |是|string |项目标识identifier |

*返回参数说明:*

|参数名|类型|说明|
|-|-|-|
|identifier |string|project's identifier|
|content |string|主页内容|
|attachments |array|附件|
|-- name |string|用户名,也是用户标识|


返回值
```
{
"content": "",
"identifier": "forgeplus",
attachments: [

]
}

```
---

#### 修改项目主页内容
```
POST api/:namespace_id/:id
```

*示例*
```
curl -X POST \
-d "content=内容" \
-d "attachment_ids=[1, 2, 2]" \
http://localhost:3000/api/:jasder/forgeplus | jq
```

*请求参数说明:*

|参数名|必选|类型|说明|
|-|-|-|-|
|namespace_id |是|string |用户登录名 |
|id |是|string |项目标识identifier |
|content |是|string |内容信息 |
|attachment_ids |是|array |附件id |

*返回参数说明:*

|参数名|类型|说明|
|-|-|-|
|identifier |string|project's identifier|
|content |string|主页内容|
|attachments |array|附件|
|-- name |string|用户名,也是用户标识|

返回值
```
{
"content": "",
"identifier": "forgeplus",
attachments: [

]
}

```
---

### 获取分支列表
```
GET /api/:namespace_id/:id/branches


+ 27
- 0
app/controllers/projects_controller.rb View File

@@ -107,6 +107,33 @@ class ProjectsController < ApplicationController
@projects = Project.recommend.includes(:repository, :project_category, owner: :user_extension).limit(5)
end

def about
@project_detail = @project.project_detail
@attachments = Array(@project_detail&.attachments) if request.get?
ActiveRecord::Base.transaction do
if request.post?
authorizate_user_can_edit_project!
unless @project_detail.present?
@project_detail = ProjectDetail.new(
content: params[:content],
project_id: @project.id)
else
@project_detail.content = params[:content]
end
if @project_detail.save!
attachment_ids = Array(params[:attachment_ids])
logger.info "=============> #{Array(params[:attachment_ids])}"
@attachments = Attachment.where(id: attachment_ids).select(:id, :container_id, :container_type)
@attachments.update_all(
container_id: @project_detail.id,
container_type: @project_detail.model_name.name,
author_id: current_user.id,
description: "")
end
end
end
end


private
def project_params


+ 1
- 0
app/models/project.rb View File

@@ -32,6 +32,7 @@ class Project < ApplicationRecord
has_many :versions, -> { order("versions.created_on DESC, versions.name DESC") }, dependent: :destroy
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_one :project_detail, dependent: :destroy
after_save :check_project_members
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}


+ 4
- 0
app/models/project_detail.rb View File

@@ -0,0 +1,4 @@
class ProjectDetail < ApplicationRecord
belongs_to :project, optional: true
has_many :attachments, as: :container, dependent: :destroy
end

+ 5
- 0
app/views/projects/about.json.jbuilder View File

@@ -0,0 +1,5 @@
json.content @project_detail&.content
json.identifier @project.identifier
json.attachments @attachments do |attach|
json.partial! "attachments/attachment_simple", locals: {attachment: attach}
end

+ 1
- 0
config/routes.rb View File

@@ -295,6 +295,7 @@ Rails.application.routes.draw do
get :watchers, to: 'projects#watch_users'
get :stargazers, to: 'projects#praise_users'
get :members, to: 'projects#fork_users'
match :about, :via => [:get, :put, :post]
end
end


+ 12
- 0
db/migrate/20201004070431_create_project_details.rb View File

@@ -0,0 +1,12 @@
class CreateProjectDetails < ActiveRecord::Migration[5.2]
def change
create_table :project_details do |t|
t.integer :project_id
t.longtext :content

t.timestamps
end

add_index :project_details, :project_id
end
end

Loading…
Cancel
Save