2020-06-07 08:28:05 +00:00
|
|
|
class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
2019-08-14 09:48:44 +00:00
|
|
|
protect_from_forgery with: :null_session
|
|
|
|
|
|
|
|
before_action :check_authorization
|
|
|
|
before_action :fetch_contact, only: [:show, :update]
|
|
|
|
|
|
|
|
def index
|
2020-06-07 08:28:05 +00:00
|
|
|
@contacts = Current.account.contacts
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
2019-10-20 08:47:26 +00:00
|
|
|
def show; end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def create
|
2020-06-07 08:28:05 +00:00
|
|
|
@contact = Current.account.contacts.new(contact_create_params)
|
2019-08-14 09:48:44 +00:00
|
|
|
@contact.save!
|
|
|
|
render json: @contact
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-12-10 04:59:35 +00:00
|
|
|
@contact.update!(contact_params)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_authorization
|
|
|
|
authorize(Contact)
|
|
|
|
end
|
|
|
|
|
|
|
|
def contact_params
|
|
|
|
params.require(:contact).permit(:name, :email, :phone_number)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_contact
|
2020-06-07 08:28:05 +00:00
|
|
|
@contact = Current.account.contacts.find(params[:id])
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def contact_create_params
|
2020-06-07 08:28:05 +00:00
|
|
|
params.require(:contact).permit(:name, :email, :phone_number)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
2019-10-20 08:47:26 +00:00
|
|
|
end
|