Browse Source

Merge remote-tracking branch 'origin/develop' into standalone_develop

pull/313/head
viletyy 3 years ago
parent
commit
6bb1dcf718
4 changed files with 19 additions and 6 deletions
  1. +1
    -0
      app/docs/slate/source/includes/_pulls.md
  2. +1
    -0
      app/models/journal.rb
  3. +10
    -6
      app/services/api/v1/projects/pulls/journals/list_service.rb
  4. +7
    -0
      public/docs/api.html

+ 1
- 0
app/docs/slate/source/includes/_pulls.md View File

@@ -1249,6 +1249,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/journals.json')
|state |否| |string |状态, opened: 开启的, resolved: 已解决的, disabled: 无效的|
|parent_id |否| |integer|父评论ID|
|path |否| |string |评论文件路径|
|is_full |否| |bool |是否展示全部评论(包括回复)|
|sort_by |否|created_on|string |排序字段 created_on: 创建时间, updated_on: 更新时间|
|sort_direction |否|asc |string |排序类型 desc: 倒序, asc: 正序|



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

@@ -42,6 +42,7 @@ class Journal < ApplicationRecord
belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true
has_many :journal_details, :dependent => :delete_all
has_many :attachments, as: :container, dependent: :destroy
has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id

scope :journal_includes, ->{includes(:user, :journal_details, :attachments)}
scope :parent_journals, ->{where(parent_id: nil)}


+ 10
- 6
app/services/api/v1/projects/pulls/journals/list_service.rb View File

@@ -1,12 +1,13 @@
class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
include ActiveModel::Model
attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :path, :sort_by, :sort_direction, :user
attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :path, :is_full, :sort_by, :sort_direction, :user
attr_accessor :queried_journals

validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}
validates :need_respond, inclusion: {in: [true, false], message: '请输入正确的NeedRespond'}, allow_nil: true
validates :is_full, inclusion: {in: [true, false], message: '请输入正确的IsFull'}
validates :state, inclusion: {in: %w(opened resolved disabled)}, allow_nil: true

def initialize(project, pull_request, params, user)
@@ -19,6 +20,7 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
@parent_id = params[:parent_id]
@sort_by = params[:sort_by] || 'created_on'
@sort_direction = params[:sort_direction] || 'asc'
@is_full = ActiveModel::Type::Boolean.new.cast(params[:is_full]) || false
@path = params[:path]
@user = user
end
@@ -33,10 +35,12 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
private
def journal_query_data
journals = @pull_request.journals
if parent_id.present?
journals = journals.where(parent_id: parent_id)
else
journals = journals.parent_journals
if !is_full
if parent_id.present?
journals = journals.where(parent_id: parent_id)
else
journals = journals.parent_journals
end
end

journals = journals.where(review_id: review_id) if review_id.present?
@@ -45,7 +49,7 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
journals = journals.where(path: path) if path.present?

q = journals.ransack(notes_cont: keyword)
scope = q.result.includes(:user, :resolveer, review: [:reviewer, pull_request: :issue])
scope = q.result.includes(:user, :resolveer, :children_journals, review: [:reviewer, pull_request: :issue])
scope = scope.order("journals.#{sort_by} #{sort_direction}")

@queried_journals = scope


+ 7
- 0
public/docs/api.html View File

@@ -15079,6 +15079,13 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json
<td>评论文件路径</td>
</tr>
<tr>
<td>is_full</td>
<td>否</td>
<td></td>
<td>bool</td>
<td>是否展示全部评论(包括回复)</td>
</tr>
<tr>
<td>sort_by</td>
<td>否</td>
<td>created_on</td>


Loading…
Cancel
Save