fix: new endpoint for the text search
This commit is contained in:
parent
c03a6602f3
commit
1a2349ae84
3 changed files with 29 additions and 15 deletions
|
@ -2,8 +2,8 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||||
include Events::Types
|
include Events::Types
|
||||||
include DateRangeHelper
|
include DateRangeHelper
|
||||||
|
|
||||||
before_action :conversation, except: [:index, :meta, :search, :create, :filter]
|
before_action :conversation, except: [:index, :meta, :search, :create, :filter, :text_search]
|
||||||
before_action :inbox, :contact, :contact_inbox, only: [:create]
|
before_action :inbox, :contact, :contact_inbox, :text_search, only: [:create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
result = conversation_finder.perform
|
result = conversation_finder.perform
|
||||||
|
@ -12,7 +12,7 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_search
|
def text_search
|
||||||
@result = conversation_finder.search
|
@result = conversation_finder.text_search
|
||||||
end
|
end
|
||||||
|
|
||||||
def meta
|
def meta
|
||||||
|
|
|
@ -44,6 +44,14 @@ class ConversationFinder
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def text_search
|
||||||
|
{
|
||||||
|
messages: filter_messages,
|
||||||
|
conversations: filter_conversations,
|
||||||
|
contacts: filter_contacts
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_up
|
def set_up
|
||||||
|
@ -103,12 +111,12 @@ class ConversationFinder
|
||||||
@conversations
|
@conversations
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def filter_by_query
|
||||||
{
|
allowed_message_types = [Message.message_types[:incoming], Message.message_types[:outgoing]]
|
||||||
messages: filter_messages,
|
@conversations = conversations.joins(:messages).where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||||
conversations: filter_conversations,
|
.where(messages: { message_type: allowed_message_types }).includes(:messages)
|
||||||
contacts: filter_contacts
|
.where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||||
}
|
.where(messages: { message_type: allowed_message_types })
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_by_query
|
def filter_by_query
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
json.payload do
|
json.payload do
|
||||||
|
json.conversations do
|
||||||
json.array! @result[:conversations] do |conversation|
|
json.array! @result[:conversations] do |conversation|
|
||||||
json.partial! 'api/v1/models/conversation', formats: [:json], conversation: conversation
|
json.partial! 'api/v1/models/conversation', formats: [:json], conversation: conversation
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
json.contacts do
|
||||||
json.array! @result[:contacts] do |contact|
|
json.array! @result[:contacts] do |contact|
|
||||||
json.partial! 'api/v1/models/contact', formats: [:json], resource: contact
|
json.partial! 'api/v1/models/contact', formats: [:json], resource: contact
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
json.messages do
|
||||||
json.array! @result[:messages] do |message|
|
json.array! @result[:messages] do |message|
|
||||||
json.partial! 'api/v1/models/message', formats: [:json], message: message
|
json.partial! 'api/v1/models/message', formats: [:json], message: message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue