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 DateRangeHelper
|
||||
|
||||
before_action :conversation, except: [:index, :meta, :search, :create, :filter]
|
||||
before_action :inbox, :contact, :contact_inbox, only: [:create]
|
||||
before_action :conversation, except: [:index, :meta, :search, :create, :filter, :text_search]
|
||||
before_action :inbox, :contact, :contact_inbox, :text_search, only: [:create]
|
||||
|
||||
def index
|
||||
result = conversation_finder.perform
|
||||
|
@ -12,7 +12,7 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
|||
end
|
||||
|
||||
def text_search
|
||||
@result = conversation_finder.search
|
||||
@result = conversation_finder.text_search
|
||||
end
|
||||
|
||||
def meta
|
||||
|
|
|
@ -44,6 +44,14 @@ class ConversationFinder
|
|||
}
|
||||
end
|
||||
|
||||
def text_search
|
||||
{
|
||||
messages: filter_messages,
|
||||
conversations: filter_conversations,
|
||||
contacts: filter_contacts
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_up
|
||||
|
@ -103,12 +111,12 @@ class ConversationFinder
|
|||
@conversations
|
||||
end
|
||||
|
||||
def search
|
||||
{
|
||||
messages: filter_messages,
|
||||
conversations: filter_conversations,
|
||||
contacts: filter_contacts
|
||||
}
|
||||
def filter_by_query
|
||||
allowed_message_types = [Message.message_types[:incoming], Message.message_types[:outgoing]]
|
||||
@conversations = conversations.joins(:messages).where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||
.where(messages: { message_type: allowed_message_types }).includes(:messages)
|
||||
.where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||
.where(messages: { message_type: allowed_message_types })
|
||||
end
|
||||
|
||||
def filter_by_query
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
json.payload do
|
||||
json.array! @result[:conversations] do |conversation|
|
||||
json.partial! 'api/v1/models/conversation', formats: [:json], conversation: conversation
|
||||
json.conversations do
|
||||
json.array! @result[:conversations] do |conversation|
|
||||
json.partial! 'api/v1/models/conversation', formats: [:json], conversation: conversation
|
||||
end
|
||||
end
|
||||
|
||||
json.array! @result[:contacts] do |contact|
|
||||
json.partial! 'api/v1/models/contact', formats: [:json], resource: contact
|
||||
json.contacts do
|
||||
json.array! @result[:contacts] do |contact|
|
||||
json.partial! 'api/v1/models/contact', formats: [:json], resource: contact
|
||||
end
|
||||
end
|
||||
|
||||
json.array! @result[:messages] do |message|
|
||||
json.partial! 'api/v1/models/message', formats: [:json], message: message
|
||||
json.messages do
|
||||
json.array! @result[:messages] do |message|
|
||||
json.partial! 'api/v1/models/message', formats: [:json], message: message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue