add: pinned projects order by position

This commit is contained in:
vilet.yy 2021-06-02 16:40:40 +08:00 committed by viletyy
parent 7ba45bc866
commit 16c293562a
5 changed files with 134 additions and 26 deletions

View File

@ -1,7 +1,7 @@
class Users::IsPinnedProjectsController < Users::BaseController
before_action :private_user_resources!, only: [:pin]
def index
@is_pinned_projects = observed_user.is_pinned_projects.includes(:project_category, :project_language, :repository).order(position: :desc)
@is_pinned_projects = observed_user.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc)
@is_pinned_projects = kaminari_paginate(@is_pinned_projects)
end
@ -15,6 +15,19 @@ class Users::IsPinnedProjectsController < Users::BaseController
tip_exception(e.message)
end
def update
@pinned_project = PinnedProject.find_by_id(params[:id])
@pinned_project.attributes = pinned_project_params
if @pinned_project.save
render_ok
else
render_error
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
private
def is_pinned_project_ids
if params[:is_pinned_project_ids].present?
@ -25,4 +38,8 @@ class Users::IsPinnedProjectsController < Users::BaseController
return observed_user.is_pinned_project_ids.include?(params[:is_pinned_project_id].to_i) ? observed_user.is_pinned_project_ids : observed_user.is_pinned_project_ids.push(params[:is_pinned_project_id].to_i)
end
end
def pinned_project_params
params.require(:pinned_project).permit(:position)
end
end

View File

@ -1,7 +1,7 @@
<!--
* @Date: 2021-03-01 10:35:21
* @LastEditors: viletyy
* @LastEditTime: 2021-06-01 10:06:08
* @LastEditTime: 2021-06-02 16:40:02
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
-->
# Users
@ -53,7 +53,7 @@ await octokit.request('GET /api/users/me.json')
> 示例:
```shell
curl -X POST http://localhost:3000/api/users/yystopf.json
curl -X PATCH/PUT http://localhost:3000/api/users/yystopf.json
```
```javascript
@ -141,6 +141,7 @@ await octokit.request('GET /api/users/:login/is_pinned_projects.json')
|author.image_url |string |项目拥有者头像|
|category.name |string |项目分类名称|
|language.name |string |项目语言名称|
|position |int |项目排序|
> 返回的JSON示例:
@ -228,6 +229,45 @@ await octokit.request('GET /api/users/:login/is_pinned_projects/pin.json')
```
## 星标项目展示排序
星标项目展示排序
> 示例:
```shell
curl -X PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
```
```javascript
await octokit.request('PATCH/PUT /api/users/:login/is_pinned_projects/:id.json')
```
### HTTP 请求
`PATCH/PUT /api/users/:login/is_pinned_projects/:id.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|pinned_projects.position |int |排序,数字越大排名越前 |
> 请求的JSON示例
```json
{
"pinned_project": {
"position": 1
}
}
```
> 返回的JSON示例:
```json
{
"status": 0,
"message": "success"
}
```
## 用户近期活动统计
用户近期活动统计, 默认显示近一周的数据

View File

@ -1,4 +1,6 @@
json.total_count @is_pinned_projects.total_count
json.projects @is_pinned_projects.each do |project|
json.partial! "projects/project_detail", project: project
json.partial! "projects/project_detail", project: project&.project
json.id project.id
json.position project.position
end

View File

@ -266,7 +266,7 @@ Rails.application.routes.draw do
end
end
resources :headmaps, only: [:index]
resources :is_pinned_projects, only: [:index] do
resources :is_pinned_projects, only: [:index, :update] do
collection do
post :pin
end

View File

@ -340,6 +340,9 @@
<li>
<a href="#3064477f38" class="toc-h2 toc-link" data-title="用户添加星标项目">用户添加星标项目</a>
</li>
<li>
<a href="#3f31dec5ae" class="toc-h2 toc-link" data-title="星标项目展示排序">星标项目展示排序</a>
</li>
<li>
<a href="#4a39412749" class="toc-h2 toc-link" data-title="用户近期活动统计">用户近期活动统计</a>
</li>
@ -614,7 +617,7 @@ Success — a happy kitten is an authenticated kitten!
<!--
* @Date: 2021-03-01 10:35:21
* @LastEditors: viletyy
* @LastEditTime: 2021-06-01 10:06:08
* @LastEditTime: 2021-06-02 16:40:02
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
-->
<h1 id='users'>Users</h1><h2 id='1ae74893b1'>获取当前登陆用户信息</h2>
@ -682,7 +685,7 @@ Success — a happy kitten is an authenticated kitten!
<blockquote>
<p>示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> POST http://localhost:3000/api/users/yystopf.json
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> PATCH/PUT http://localhost:3000/api/users/yystopf.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">PATCH/PUT /api/users/:login.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-2'>HTTP 请求</h3>
<p><code>PATCH/PUT /api/users/:login.json</code></p>
@ -887,6 +890,11 @@ Success — a happy kitten is an authenticated kitten!
<td>string</td>
<td>项目语言名称</td>
</tr>
<tr>
<td>position</td>
<td>int</td>
<td>项目排序</td>
</tr>
</tbody></table>
<blockquote>
@ -975,6 +983,47 @@ Success — a happy kitten is an authenticated kitten!
</tr>
</tbody></table>
<blockquote>
<p>返回的JSON示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight json tab-json"><code><span class="p">{</span><span class="w">
</span><span class="nl">"status"</span><span class="p">:</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w">
</span><span class="nl">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"success"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div><h2 id='3f31dec5ae'>星标项目展示排序</h2>
<p>星标项目展示排序</p>
<blockquote>
<p>示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">PATCH/PUT /api/users/:login/is_pinned_projects/:id.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-5'>HTTP 请求</h3>
<p><code>PATCH/PUT /api/users/:login/is_pinned_projects/:id.json</code></p>
<h3 id='aa883f5d52-3'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>字段说明</th>
</tr>
</thead><tbody>
<tr>
<td>pinned_projects.position</td>
<td>int</td>
<td>排序,数字越大排名越前</td>
</tr>
</tbody></table>
<blockquote>
<p>请求的JSON示例</p>
</blockquote>
<div class="highlight"><pre class="highlight json tab-json"><code><span class="p">{</span><span class="w">
</span><span class="nl">"pinned_project"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="nl">"position"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div>
<blockquote>
<p>返回的JSON示例:</p>
</blockquote>
@ -990,7 +1039,7 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/statistics/activity.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/statistics/activity.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-5'>HTTP 请求</h3>
</code></pre></div><h3 id='http-6'>HTTP 请求</h3>
<p><code>GET /api/users/:login/statistics/activity.json</code></p>
<h3 id='7447e4874e-3'>返回字段说明:</h3>
<table><thead>
@ -1079,9 +1128,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/headmaps.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/headmaps.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-6'>HTTP 请求</h3>
</code></pre></div><h3 id='http-7'>HTTP 请求</h3>
<p><code>GET api/users/:login/headmaps.json</code></p>
<h3 id='aa883f5d52-3'>请求字段说明:</h3>
<h3 id='aa883f5d52-4'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -1224,9 +1273,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/project_trends.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/project_trends.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-7'>HTTP 请求</h3>
</code></pre></div><h3 id='http-8'>HTTP 请求</h3>
<p><code>GET api/users/:login/project_trends.json</code></p>
<h3 id='aa883f5d52-4'>请求字段说明:</h3>
<h3 id='aa883f5d52-5'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -1541,9 +1590,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/statistics/develop.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/statistics/develop.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-8'>HTTP 请求</h3>
</code></pre></div><h3 id='http-9'>HTTP 请求</h3>
<p><code>GET /api/users/:login/statistics/develop.json</code></p>
<h3 id='aa883f5d52-5'>请求字段说明:</h3>
<h3 id='aa883f5d52-6'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -1684,9 +1733,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/statistics/role.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/statistics/role.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-9'>HTTP 请求</h3>
</code></pre></div><h3 id='http-10'>HTTP 请求</h3>
<p><code>GET /api/users/:login/statistics/role.json</code></p>
<h3 id='aa883f5d52-6'>请求字段说明:</h3>
<h3 id='aa883f5d52-7'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -1766,9 +1815,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/statistics/major.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/statistics/major.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-10'>HTTP 请求</h3>
</code></pre></div><h3 id='http-11'>HTTP 请求</h3>
<p><code>GET /api/users/:login/statistics/major.json</code></p>
<h3 id='aa883f5d52-7'>请求字段说明:</h3>
<h3 id='aa883f5d52-8'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -1827,9 +1876,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/applied_messages.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/applied_messages.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-11'>HTTP 请求</h3>
</code></pre></div><h3 id='http-12'>HTTP 请求</h3>
<p><code>GET /api/users/:login/applied_messages.json</code></p>
<h3 id='aa883f5d52-8'>请求字段说明:</h3>
<h3 id='aa883f5d52-9'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -2064,9 +2113,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET http://localhost:3000/api/users/yystopf/applied_transfer_projects.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/applied_transfer_projects.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-12'>HTTP 请求</h3>
</code></pre></div><h3 id='http-13'>HTTP 请求</h3>
<p><code>GET /api/users/:login/applied_transfer_projects.json</code></p>
<h3 id='aa883f5d52-9'>请求字段说明:</h3>
<h3 id='aa883f5d52-10'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -2256,9 +2305,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/accept.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/applied_transfer_projects/:id/accept.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-13'>HTTP 请求</h3>
</code></pre></div><h3 id='http-14'>HTTP 请求</h3>
<p><code>GET /api/users/:login/applied_transfer_projects/:id/accept.json</code></p>
<h3 id='aa883f5d52-10'>请求字段说明:</h3>
<h3 id='aa883f5d52-11'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>
@ -2447,9 +2496,9 @@ Success — a happy kitten is an authenticated kitten!
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/refuse.json
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/users/:login/applied_transfer_projects/:id/refuse.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-14'>HTTP 请求</h3>
</code></pre></div><h3 id='http-15'>HTTP 请求</h3>
<p><code>GET /api/users/:login/applied_transfer_projects/:id/refuse.json</code></p>
<h3 id='aa883f5d52-11'>请求字段说明:</h3>
<h3 id='aa883f5d52-12'>请求字段说明:</h3>
<table><thead>
<tr>
<th>参数</th>