summaryrefslogtreecommitdiff
path: root/lib/api/notes.rb
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-11-30 09:52:58 +0000
committerPhil Hughes <me@iamphill.com>2017-11-30 09:52:58 +0000
commit386cbf22ee8fc1d206e76f0f34568379ae726e02 (patch)
tree4976d52023637beaa5046035b64554dd451f0d27 /lib/api/notes.rb
parent1880809d8ef9b650d1af615ebbaa590626ccf17f (diff)
parent73e48b745c34c048c56abf28e6c278707d9bd2f3 (diff)
downloadgitlab-ce-386cbf22ee8fc1d206e76f0f34568379ae726e02.tar.gz
Merge branch 'master' into multi-file-editor-dirty-diff-indicator
Diffstat (limited to 'lib/api/notes.rb')
-rw-r--r--lib/api/notes.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index ceaaeca4046..3588dc85c9e 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -18,6 +18,10 @@ module API
end
params do
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
+ optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at',
+ desc: 'Return notes ordered by `created_at` or `updated_at` fields.'
+ optional :sort, type: String, values: %w[asc desc], default: 'desc',
+ desc: 'Return notes sorted in `asc` or `desc` order.'
use :pagination
end
get ":id/#{noteables_str}/:noteable_id/notes" do
@@ -29,11 +33,12 @@ module API
# at the DB query level (which we cannot in that case), the current
# page can have less elements than :per_page even if
# there's more than one page.
+ raw_notes = noteable.notes.with_metadata.reorder(params[:order_by] => params[:sort])
notes =
# paginate() only works with a relation. This could lead to a
# mismatch between the pagination headers info and the actual notes
# array returned, but this is really a edge-case.
- paginate(noteable.notes.with_metadata)
+ paginate(raw_notes)
.reject { |n| n.cross_reference_not_visible_for?(current_user) }
present notes, with: Entities::Note
else