- Cria modelo LeadClick para registrar cliques das landing pages - Cria modelo LandingHost para mapear hostname → inbox_id - Endpoint público POST /track/click para receber eventos de clique - Leads::AttributionMatcherService para correlacionar clique com conversa - Integração com IncomingMessageWuzapiService para atribuição automática - API REST para gerenciar LandingHosts por inbox (index/create/destroy) - UI: nova aba 'Landing Pages' nas configurações da caixa de entrada - Dashboard API client dedicado (landingHosts.js) - RuboCop: refatora shift_signature_name, TrackingController, AttributionMatcherService e WuzapiService
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
class Api::V1::Accounts::LandingHostsController < Api::V1::Accounts::BaseController
|
|
before_action :fetch_inbox, only: [:index, :create]
|
|
before_action :fetch_landing_host, only: [:destroy]
|
|
|
|
def index
|
|
@landing_hosts = LandingHost.where(inbox_id: @inbox.id)
|
|
render json: @landing_hosts
|
|
end
|
|
|
|
def create
|
|
@landing_host = LandingHost.new(landing_host_params.merge(inbox_id: @inbox.id, active: true))
|
|
|
|
if @landing_host.save
|
|
render json: @landing_host, status: :created
|
|
else
|
|
render json: { error: @landing_host.errors.full_messages }, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@landing_host.destroy!
|
|
head :no_content
|
|
end
|
|
|
|
private
|
|
|
|
def fetch_inbox
|
|
@inbox = Current.account.inboxes.find(params[:inbox_id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
render json: { error: 'Inbox not found' }, status: :not_found
|
|
end
|
|
|
|
def fetch_landing_host
|
|
# Garantimos que a pessoa só possa apagar LandingHosts de Inboxes que pertencem a ela
|
|
valid_inbox_ids = Current.account.inboxes.pluck(:id)
|
|
@landing_host = LandingHost.where(inbox_id: valid_inbox_ids).find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
render json: { error: 'Landing Host not found' }, status: :not_found
|
|
end
|
|
|
|
def landing_host_params
|
|
params.require(:landing_host).permit(:hostname, :unit_code, :active)
|
|
end
|
|
end
|