Class: Doodle::ConversationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/doodle/conversations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#auth_params, #authenticate, #authenticate_user

Instance Method Details

#channel_finder_serviceObject



17
18
19
# File 'app/controllers/doodle/conversations_controller.rb', line 17

def channel_finder_service
  @channel_finder_service ||= Channel::FinderService.new({name: params.require(:channel)})
end

#conversation_creator_service(participants) ⇒ Object



25
26
27
# File 'app/controllers/doodle/conversations_controller.rb', line 25

def conversation_creator_service(participants)
  @conversation_creator_service ||= ::Layer::Conversation::CreatorService.new(participants)
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/doodle/conversations_controller.rb', line 5

def create
  channel  = channel_finder_service.call.first

  if channel.present?
    conversation = conversation_creator_service([params.require(:login)]).call
    protocol = protocol_creator_service(channel, conversation).call
    render json: { protocol_id: protocol.id, prococol_status: protocol.status, channel: channel.name, conversation_id: conversation.id }, status: 201
  else
    render json: { error: 'Channel dont found, Please create channel with this name first' }
  end
end

#protocol_creator_service(channel, conversation) ⇒ Object



21
22
23
# File 'app/controllers/doodle/conversations_controller.rb', line 21

def protocol_creator_service(channel, conversation)
  @protocol_creator_service ||= Protocol::CreatorService.new(params.require(:login), channel, conversation)
end