Feature: API to get most used labels (#447)
* Add most-used labels API * Filter conversation by labels * Move match_all to any query Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
@@ -2,4 +2,8 @@ class Api::V1::LabelsController < Api::BaseController
|
||||
def index # list all labels in account
|
||||
@labels = current_account.all_conversation_tags
|
||||
end
|
||||
|
||||
def most_used
|
||||
@labels = ActsAsTaggableOn::Tag.most_used(params[:count] || 10)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,6 +31,7 @@ class ConversationFinder
|
||||
|
||||
find_all_conversations
|
||||
filter_by_status
|
||||
filter_by_labels if params[:labels]
|
||||
|
||||
mine_count, unassigned_count, all_count = set_count_for_all_conversations
|
||||
|
||||
@@ -62,7 +63,6 @@ class ConversationFinder
|
||||
|
||||
def set_assignee_type
|
||||
@assignee_type_id = ASSIGNEE_TYPES[ASSIGNEE_TYPES_BY_ID[params[:assignee_type_id].to_i]]
|
||||
# ente budhiparamaya neekam kandit enthu tonunu? ;)
|
||||
end
|
||||
|
||||
def find_all_conversations
|
||||
@@ -86,6 +86,10 @@ class ConversationFinder
|
||||
@conversations = @conversations.where(status: params[:status] || DEFAULT_STATUS)
|
||||
end
|
||||
|
||||
def filter_by_labels
|
||||
@conversations = @conversations.tagged_with(params[:labels], any: true)
|
||||
end
|
||||
|
||||
def set_count_for_all_conversations
|
||||
[
|
||||
@conversations.assigned_to(current_user).count,
|
||||
|
||||
3
app/views/api/v1/labels/most_used.json.jbuilder
Normal file
3
app/views/api/v1/labels/most_used.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
||||
json.payload do
|
||||
json.labels @labels
|
||||
end
|
||||
Reference in New Issue
Block a user