forked from Gitlink/forgeplus
ADD recommand projects api
This commit is contained in:
parent
7f9316075c
commit
c6a7719d4d
59
README.md
59
README.md
|
@ -1364,6 +1364,65 @@ http://localhost:3000/api/projects | jq
|
|||
```
|
||||
---
|
||||
|
||||
#### 推荐项目
|
||||
```
|
||||
GET api/projects/recommend
|
||||
```
|
||||
*示例*
|
||||
```
|
||||
curl -X GET \
|
||||
http://localhost:3000/api/projects/recommend | jq
|
||||
```
|
||||
|
||||
*返回参数说明:*
|
||||
|
||||
|参数名|类型|说明|
|
||||
|-|-|-|
|
||||
|total_count |int |项目总条数 |
|
||||
|id |string |项目id |
|
||||
|name |string|项目名称|
|
||||
|description |string|项目简介|
|
||||
|visits |int|流量数|
|
||||
|forked_count |int|被fork的数量|
|
||||
|praises_count |int|star数量|
|
||||
|is_public |boolean|是否公开, true:公开,false:未公开|
|
||||
|mirror_url |string|镜像url|
|
||||
|last_update_time|int|最后更新时间,为UNIX格式的时间戳|
|
||||
|author |object|项目创建者|
|
||||
|-- name |string|用户名,也是用户标识|
|
||||
|category |object|项目类别|
|
||||
|-- id |int|项目类型id|
|
||||
|-- name |string|项目类型名称|
|
||||
|language |object|项目语言|
|
||||
|-- id |int|项目语言id|
|
||||
|-- name |string|项目语言名称|
|
||||
|
||||
|
||||
返回值
|
||||
```
|
||||
[
|
||||
{
|
||||
"id": 20,
|
||||
"repo_id": null,
|
||||
"identifier": "PNAekinmH",
|
||||
"name": "FNILL",
|
||||
"visits": 13567,
|
||||
"author": {
|
||||
"name": "王一达",
|
||||
"login": "wangyida",
|
||||
"image_url": "avatars/User/b"
|
||||
},
|
||||
"category": {
|
||||
"id": 8,
|
||||
"name": "其他"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
```
|
||||
---
|
||||
|
||||
### 获取分支列表
|
||||
```
|
||||
GET /api/:namespace_id/:id/branches
|
||||
|
|
|
@ -2,8 +2,8 @@ class ProjectsController < ApplicationController
|
|||
include ApplicationHelper
|
||||
include OperateProjectAbilityAble
|
||||
include ProjectsHelper
|
||||
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users]
|
||||
before_action :load_project, except: %i[index group_type_list migrate create]
|
||||
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend]
|
||||
before_action :load_project, except: %i[index group_type_list migrate create recommend]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||
|
||||
|
@ -103,6 +103,10 @@ class ProjectsController < ApplicationController
|
|||
json_response(@project)
|
||||
end
|
||||
|
||||
def recommend
|
||||
@projects = Project.recommend.includes(:repository, :project_category, owner: :user_extension).limit(5)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def project_params
|
||||
|
|
|
@ -36,6 +36,8 @@ class Project < ApplicationRecord
|
|||
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)}
|
||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
|
||||
|
||||
|
||||
|
||||
def self.search_project(search)
|
||||
|
|
|
@ -11,7 +11,7 @@ Rails.application.routes.draw do
|
|||
get 'attachments/entries/get_file', to: 'attachments#get_file'
|
||||
get 'attachments/download/:id', to: 'attachments#show'
|
||||
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
||||
|
||||
|
||||
get 'auth/qq/callback', to: 'oauth/qq#create'
|
||||
get 'auth/failure', to: 'oauth/base#auth_failure'
|
||||
get 'auth/cas/callback', to: 'oauth/cas#create'
|
||||
|
@ -19,7 +19,7 @@ Rails.application.routes.draw do
|
|||
get 'oauth/bind', to: 'oauth/educoder#bind'
|
||||
get 'oauth/register', to: 'oauth#register'
|
||||
post 'oauth/auto_register', to: 'oauth#auto_register'
|
||||
|
||||
|
||||
resources :edu_settings
|
||||
|
||||
scope '/api' do
|
||||
|
@ -33,7 +33,7 @@ Rails.application.routes.draw do
|
|||
resources :compose_projects, only: [:create, :destroy]
|
||||
end
|
||||
resources :attachments do
|
||||
member do
|
||||
member do
|
||||
post :preview_attachment
|
||||
end
|
||||
collection do
|
||||
|
@ -89,6 +89,7 @@ Rails.application.routes.draw do
|
|||
collection do
|
||||
post :migrate
|
||||
get :group_type_list
|
||||
get :recommend
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue