diff options
author | Hiroyuki Sato <sathiroyuki@gmail.com> | 2017-08-30 10:48:55 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-08-30 10:48:55 +0300 |
commit | 7187395ef13d8d84a145d1b5251882ebada3f7f2 (patch) | |
tree | 06188448a7059648d5ca99c159f525eaf3499cc3 /app/controllers/autocomplete_controller.rb | |
parent | df8ca5aaab21f47c328cc15f2c454b9cc97a3ed5 (diff) |
Add filter by my reaction
Diffstat (limited to 'app/controllers/autocomplete_controller.rb')
-rw-r--r-- | app/controllers/autocomplete_controller.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb index 3120916c5bb..54f78fc8719 100644 --- a/app/controllers/autocomplete_controller.rb +++ b/app/controllers/autocomplete_controller.rb @@ -1,5 +1,7 @@ class AutocompleteController < ApplicationController - skip_before_action :authenticate_user!, only: [:users] + AWARD_EMOJI_MAX = 100 + + skip_before_action :authenticate_user!, only: [:users, :award_emojis] before_action :load_project, only: [:users] before_action :find_users, only: [:users] @@ -48,6 +50,20 @@ class AutocompleteController < ApplicationController render json: projects.to_json(only: [:id, :name_with_namespace], methods: :name_with_namespace) end + def award_emojis + emoji_with_count = AwardEmoji + .limit(AWARD_EMOJI_MAX) + .where(user: current_user) + .group(:name) + .order(count: :desc, name: :asc) + .count + + # Transform from hash to array to guarantee json order + # e.g. { 'thumbsup' => 2, 'thumbsdown' = 1 } + # => [{ name: 'thumbsup' }, { name: 'thumbsdown' }] + render json: emoji_with_count.map { |k, v| { name: k } } + end + private def find_users |