2020-06-07 08:28:05 +00:00
|
|
|
class Api::V1::Accounts::CannedResponsesController < Api::V1::Accounts::BaseController
|
2019-08-14 09:48:44 +00:00
|
|
|
before_action :fetch_canned_response, only: [:update, :destroy]
|
|
|
|
|
|
|
|
def index
|
|
|
|
render json: canned_responses
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-06-07 08:28:05 +00:00
|
|
|
@canned_response = Current.account.canned_responses.new(canned_response_params)
|
2019-08-14 09:48:44 +00:00
|
|
|
@canned_response.save!
|
|
|
|
render json: @canned_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-12-10 04:59:35 +00:00
|
|
|
@canned_response.update!(canned_response_params)
|
2019-08-14 09:48:44 +00:00
|
|
|
render json: @canned_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@canned_response.destroy
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_canned_response
|
2020-06-07 08:28:05 +00:00
|
|
|
@canned_response = Current.account.canned_responses.find(params[:id])
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def canned_response_params
|
|
|
|
params.require(:canned_response).permit(:short_code, :content)
|
|
|
|
end
|
|
|
|
|
|
|
|
def canned_responses
|
|
|
|
if params[:search]
|
2021-11-26 19:18:46 +00:00
|
|
|
Current.account.canned_responses.where('short_code ILIKE :search OR content ILIKE :search', search: "%#{params[:search]}%")
|
2019-08-14 09:48:44 +00:00
|
|
|
else
|
2020-06-07 08:28:05 +00:00
|
|
|
Current.account.canned_responses
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|