feat: versão 1.5 - CRM Beta com leads, funis, campanhas e portal do cliente
This commit is contained in:
@@ -62,7 +62,7 @@ func main() {
|
||||
solutionRepo := repository.NewSolutionRepository(db)
|
||||
|
||||
// Initialize services
|
||||
authService := service.NewAuthService(userRepo, tenantRepo, cfg)
|
||||
authService := service.NewAuthService(userRepo, tenantRepo, crmRepo, cfg)
|
||||
agencyService := service.NewAgencyService(userRepo, tenantRepo, cfg, db)
|
||||
tenantService := service.NewTenantService(tenantRepo, db)
|
||||
companyService := service.NewCompanyService(companyRepo)
|
||||
@@ -73,6 +73,7 @@ func main() {
|
||||
authHandler := handlers.NewAuthHandler(authService)
|
||||
agencyProfileHandler := handlers.NewAgencyHandler(tenantRepo, cfg)
|
||||
agencyHandler := handlers.NewAgencyRegistrationHandler(agencyService, cfg)
|
||||
collaboratorHandler := handlers.NewCollaboratorHandler(userRepo, agencyService)
|
||||
tenantHandler := handlers.NewTenantHandler(tenantService)
|
||||
companyHandler := handlers.NewCompanyHandler(companyService)
|
||||
planHandler := handlers.NewPlanHandler(planService)
|
||||
@@ -81,6 +82,7 @@ func main() {
|
||||
signupTemplateHandler := handlers.NewSignupTemplateHandler(signupTemplateRepo, userRepo, tenantRepo, agencyService)
|
||||
agencyTemplateHandler := handlers.NewAgencyTemplateHandler(agencyTemplateRepo, agencyService, userRepo, tenantRepo)
|
||||
filesHandler := handlers.NewFilesHandler(cfg)
|
||||
customerPortalHandler := handlers.NewCustomerPortalHandler(crmRepo, authService, cfg)
|
||||
|
||||
// Initialize upload handler
|
||||
uploadHandler, err := handlers.NewUploadHandler(cfg)
|
||||
@@ -112,7 +114,8 @@ func main() {
|
||||
router.HandleFunc("/api/health", healthHandler.Check)
|
||||
|
||||
// Auth
|
||||
router.HandleFunc("/api/auth/login", authHandler.Login)
|
||||
router.HandleFunc("/api/auth/login", authHandler.UnifiedLogin) // Nova rota unificada
|
||||
router.HandleFunc("/api/auth/login/legacy", authHandler.Login) // Antiga rota (deprecada)
|
||||
router.HandleFunc("/api/auth/register", agencyHandler.PublicRegister).Methods("POST")
|
||||
|
||||
// Public agency template registration (for creating new agencies)
|
||||
@@ -133,6 +136,13 @@ func main() {
|
||||
// Tenant check (public)
|
||||
router.HandleFunc("/api/tenant/check", tenantHandler.CheckExists).Methods("GET")
|
||||
router.HandleFunc("/api/tenant/config", tenantHandler.GetPublicConfig).Methods("GET")
|
||||
router.HandleFunc("/api/tenants/{id}/profile", tenantHandler.GetProfile).Methods("GET")
|
||||
|
||||
// Tenant branding (protected - used by both agency and customer portal)
|
||||
router.Handle("/api/tenant/branding", middleware.RequireAnyAuthenticated(cfg)(http.HandlerFunc(tenantHandler.GetBranding))).Methods("GET")
|
||||
|
||||
// Public customer registration (for agency portal signup)
|
||||
router.HandleFunc("/api/public/customers/register", crmHandler.PublicRegisterCustomer).Methods("POST")
|
||||
|
||||
// Hash generator (dev only - remove in production)
|
||||
router.HandleFunc("/api/hash", handlers.GenerateHash).Methods("POST")
|
||||
@@ -239,6 +249,9 @@ func main() {
|
||||
// Tenant solutions (which solutions the tenant has access to)
|
||||
router.Handle("/api/tenant/solutions", authMiddleware(http.HandlerFunc(solutionHandler.GetTenantSolutions))).Methods("GET")
|
||||
|
||||
// Dashboard
|
||||
router.Handle("/api/crm/dashboard", authMiddleware(http.HandlerFunc(crmHandler.GetDashboard))).Methods("GET")
|
||||
|
||||
// Customers
|
||||
router.Handle("/api/crm/customers", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
@@ -280,6 +293,8 @@ func main() {
|
||||
crmHandler.DeleteList(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT", "PATCH", "DELETE")
|
||||
|
||||
router.Handle("/api/crm/lists/{id}/leads", authMiddleware(http.HandlerFunc(crmHandler.GetLeadsByList))).Methods("GET")
|
||||
|
||||
// Customer <-> List relationship
|
||||
router.Handle("/api/crm/customers/{customer_id}/lists/{list_id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -291,6 +306,124 @@ func main() {
|
||||
}
|
||||
}))).Methods("POST", "DELETE")
|
||||
|
||||
// Leads
|
||||
router.Handle("/api/crm/leads", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetLeads(w, r)
|
||||
case http.MethodPost:
|
||||
crmHandler.CreateLead(w, r)
|
||||
}
|
||||
}))).Methods("GET", "POST")
|
||||
|
||||
router.Handle("/api/crm/leads/export", authMiddleware(http.HandlerFunc(crmHandler.ExportLeads))).Methods("GET")
|
||||
router.Handle("/api/crm/leads/import", authMiddleware(http.HandlerFunc(crmHandler.ImportLeads))).Methods("POST")
|
||||
router.Handle("/api/crm/leads/{leadId}/stage", authMiddleware(http.HandlerFunc(crmHandler.UpdateLeadStage))).Methods("PUT")
|
||||
|
||||
router.Handle("/api/crm/leads/{id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetLead(w, r)
|
||||
case http.MethodPut, http.MethodPatch:
|
||||
crmHandler.UpdateLead(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.DeleteLead(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT", "PATCH", "DELETE")
|
||||
|
||||
// Funnels & Stages
|
||||
router.Handle("/api/crm/funnels", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.ListFunnels(w, r)
|
||||
case http.MethodPost:
|
||||
crmHandler.CreateFunnel(w, r)
|
||||
}
|
||||
}))).Methods("GET", "POST")
|
||||
|
||||
router.Handle("/api/crm/funnels/{id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetFunnel(w, r)
|
||||
case http.MethodPut:
|
||||
crmHandler.UpdateFunnel(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.DeleteFunnel(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT", "DELETE")
|
||||
|
||||
router.Handle("/api/crm/funnels/{funnelId}/stages", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.ListStages(w, r)
|
||||
case http.MethodPost:
|
||||
crmHandler.CreateStage(w, r)
|
||||
}
|
||||
}))).Methods("GET", "POST")
|
||||
|
||||
router.Handle("/api/crm/stages/{id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPut:
|
||||
crmHandler.UpdateStage(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.DeleteStage(w, r)
|
||||
}
|
||||
}))).Methods("PUT", "DELETE")
|
||||
|
||||
// Lead ingest (integrations)
|
||||
router.Handle("/api/crm/leads/ingest", authMiddleware(http.HandlerFunc(crmHandler.IngestLead))).Methods("POST")
|
||||
|
||||
// Share tokens (generate)
|
||||
router.Handle("/api/crm/customers/share-token", authMiddleware(http.HandlerFunc(crmHandler.GenerateShareToken))).Methods("POST")
|
||||
|
||||
// Share data (public endpoint - no auth required)
|
||||
router.HandleFunc("/api/crm/share/{token}", crmHandler.GetSharedData).Methods("GET")
|
||||
|
||||
// ==================== CUSTOMER PORTAL ====================
|
||||
// Customer portal login (public endpoint)
|
||||
router.HandleFunc("/api/portal/login", customerPortalHandler.Login).Methods("POST")
|
||||
|
||||
// Customer portal dashboard (requires customer auth)
|
||||
router.Handle("/api/portal/dashboard", middleware.RequireCustomer(cfg)(http.HandlerFunc(customerPortalHandler.GetPortalDashboard))).Methods("GET")
|
||||
|
||||
// Customer portal leads (requires customer auth)
|
||||
router.Handle("/api/portal/leads", middleware.RequireCustomer(cfg)(http.HandlerFunc(customerPortalHandler.GetPortalLeads))).Methods("GET")
|
||||
|
||||
// Customer portal lists (requires customer auth)
|
||||
router.Handle("/api/portal/lists", middleware.RequireCustomer(cfg)(http.HandlerFunc(customerPortalHandler.GetPortalLists))).Methods("GET")
|
||||
|
||||
// Customer portal profile (requires customer auth)
|
||||
router.Handle("/api/portal/profile", middleware.RequireCustomer(cfg)(http.HandlerFunc(customerPortalHandler.GetPortalProfile))).Methods("GET")
|
||||
|
||||
// Customer portal change password (requires customer auth)
|
||||
router.Handle("/api/portal/change-password", middleware.RequireCustomer(cfg)(http.HandlerFunc(customerPortalHandler.ChangePassword))).Methods("POST")
|
||||
|
||||
// Customer portal logo upload (requires customer auth)
|
||||
router.Handle("/api/portal/logo", middleware.RequireCustomer(cfg)(http.HandlerFunc(customerPortalHandler.UploadLogo))).Methods("POST")
|
||||
|
||||
// ==================== AGENCY COLLABORATORS ====================
|
||||
// List collaborators (requires agency auth, owner only)
|
||||
router.Handle("/api/agency/collaborators", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(collaboratorHandler.ListCollaborators))).Methods("GET")
|
||||
|
||||
// Invite collaborator (requires agency auth, owner only)
|
||||
router.Handle("/api/agency/collaborators/invite", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(collaboratorHandler.InviteCollaborator))).Methods("POST")
|
||||
|
||||
// Remove collaborator (requires agency auth, owner only)
|
||||
router.Handle("/api/agency/collaborators/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(collaboratorHandler.RemoveCollaborator))).Methods("DELETE")
|
||||
|
||||
// Generate customer portal access (agency staff)
|
||||
router.Handle("/api/crm/customers/{id}/portal-access", authMiddleware(http.HandlerFunc(crmHandler.GenerateCustomerPortalAccess))).Methods("POST")
|
||||
|
||||
// Lead <-> List relationship
|
||||
router.Handle("/api/crm/leads/{lead_id}/lists/{list_id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPost:
|
||||
crmHandler.AddLeadToList(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.RemoveLeadFromList(w, r)
|
||||
}
|
||||
}))).Methods("POST", "DELETE")
|
||||
|
||||
// Apply global middlewares: tenant -> cors -> security -> rateLimit -> router
|
||||
handler := tenantDetector(corsMiddleware(securityMiddleware(rateLimitMiddleware(router))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user