2020-12-03 04:22:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::ChatMessagesController < Api::BaseController
|
|
|
|
before_action -> { authorize_if_got_token! :read, :'read:chats' }
|
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:chats' }
|
|
|
|
|
|
|
|
before_action :require_user!
|
|
|
|
|
|
|
|
def create
|
2020-12-16 00:31:30 +00:00
|
|
|
@chat_conversation = ChatConversation.find(chat_params[:chat_conversation_id])
|
|
|
|
@chat = PostChatMessageService.new.call(current_user.account, text: chat_params[:text], chat_conversation: @chat_conversation)
|
2020-12-03 04:22:51 +00:00
|
|
|
render json: @chat, serializer: REST::ChatMessageSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-12-16 00:31:30 +00:00
|
|
|
@chat = DeleteChatMessageService.new.call(current_user.account, params[:id])
|
2020-12-03 04:22:51 +00:00
|
|
|
render json: @chat, serializer: REST::ChatMessageSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def chat_params
|
|
|
|
params.permit(:text, :chat_conversation_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|