chore(release): snapshot 1.4.2
This commit is contained in:
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
func initDB(cfg *config.Config) (*sql.DB, error) {
|
||||
connStr := fmt.Sprintf(
|
||||
"host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
|
||||
"host=%s port=%s user=%s password=%s dbname=%s sslmode=disable client_encoding=UTF8",
|
||||
cfg.Database.Host,
|
||||
cfg.Database.Port,
|
||||
cfg.Database.User,
|
||||
@@ -58,11 +58,13 @@ func main() {
|
||||
agencyTemplateRepo := repository.NewAgencyTemplateRepository(db)
|
||||
planRepo := repository.NewPlanRepository(db)
|
||||
subscriptionRepo := repository.NewSubscriptionRepository(db)
|
||||
crmRepo := repository.NewCRMRepository(db)
|
||||
solutionRepo := repository.NewSolutionRepository(db)
|
||||
|
||||
// Initialize services
|
||||
authService := service.NewAuthService(userRepo, tenantRepo, cfg)
|
||||
agencyService := service.NewAgencyService(userRepo, tenantRepo, cfg)
|
||||
tenantService := service.NewTenantService(tenantRepo)
|
||||
agencyService := service.NewAgencyService(userRepo, tenantRepo, cfg, db)
|
||||
tenantService := service.NewTenantService(tenantRepo, db)
|
||||
companyService := service.NewCompanyService(companyRepo)
|
||||
planService := service.NewPlanService(planRepo, subscriptionRepo)
|
||||
|
||||
@@ -74,6 +76,8 @@ func main() {
|
||||
tenantHandler := handlers.NewTenantHandler(tenantService)
|
||||
companyHandler := handlers.NewCompanyHandler(companyService)
|
||||
planHandler := handlers.NewPlanHandler(planService)
|
||||
crmHandler := handlers.NewCRMHandler(crmRepo)
|
||||
solutionHandler := handlers.NewSolutionHandler(solutionRepo)
|
||||
signupTemplateHandler := handlers.NewSignupTemplateHandler(signupTemplateRepo, userRepo, tenantRepo, agencyService)
|
||||
agencyTemplateHandler := handlers.NewAgencyTemplateHandler(agencyTemplateRepo, agencyService, userRepo, tenantRepo)
|
||||
filesHandler := handlers.NewFilesHandler(cfg)
|
||||
@@ -84,6 +88,9 @@ func main() {
|
||||
log.Fatalf("❌ Erro ao inicializar upload handler: %v", err)
|
||||
}
|
||||
|
||||
// Initialize backup handler
|
||||
backupHandler := handlers.NewBackupHandler()
|
||||
|
||||
// Create middleware chain
|
||||
tenantDetector := middleware.TenantDetector(tenantRepo)
|
||||
corsMiddleware := middleware.CORS(cfg)
|
||||
@@ -140,6 +147,12 @@ func main() {
|
||||
router.HandleFunc("/api/admin/agencies", tenantHandler.ListAll).Methods("GET")
|
||||
router.HandleFunc("/api/admin/agencies/{id}", agencyHandler.HandleAgency).Methods("GET", "PATCH", "DELETE")
|
||||
|
||||
// SUPERADMIN: Backup & Restore
|
||||
router.Handle("/api/superadmin/backups", authMiddleware(http.HandlerFunc(backupHandler.ListBackups))).Methods("GET")
|
||||
router.Handle("/api/superadmin/backup/create", authMiddleware(http.HandlerFunc(backupHandler.CreateBackup))).Methods("POST")
|
||||
router.Handle("/api/superadmin/backup/restore", authMiddleware(http.HandlerFunc(backupHandler.RestoreBackup))).Methods("POST")
|
||||
router.Handle("/api/superadmin/backup/download/{filename}", authMiddleware(http.HandlerFunc(backupHandler.DownloadBackup))).Methods("GET")
|
||||
|
||||
// SUPERADMIN: Agency template management
|
||||
router.Handle("/api/admin/agency-templates", authMiddleware(http.HandlerFunc(agencyTemplateHandler.ListTemplates))).Methods("GET")
|
||||
router.Handle("/api/admin/agency-templates", authMiddleware(http.HandlerFunc(agencyTemplateHandler.CreateTemplate))).Methods("POST")
|
||||
@@ -167,6 +180,37 @@ func main() {
|
||||
// SUPERADMIN: Plans management
|
||||
planHandler.RegisterRoutes(router)
|
||||
|
||||
// SUPERADMIN: Solutions management
|
||||
router.Handle("/api/admin/solutions", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
solutionHandler.GetAllSolutions(w, r)
|
||||
case http.MethodPost:
|
||||
solutionHandler.CreateSolution(w, r)
|
||||
}
|
||||
}))).Methods("GET", "POST")
|
||||
|
||||
router.Handle("/api/admin/solutions/{id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
solutionHandler.GetSolution(w, r)
|
||||
case http.MethodPut, http.MethodPatch:
|
||||
solutionHandler.UpdateSolution(w, r)
|
||||
case http.MethodDelete:
|
||||
solutionHandler.DeleteSolution(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT", "PATCH", "DELETE")
|
||||
|
||||
// SUPERADMIN: Plan <-> Solutions
|
||||
router.Handle("/api/admin/plans/{plan_id}/solutions", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
solutionHandler.GetPlanSolutions(w, r)
|
||||
case http.MethodPut:
|
||||
solutionHandler.SetPlanSolutions(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT")
|
||||
|
||||
// ADMIN_AGENCIA: Client registration
|
||||
router.Handle("/api/agencies/clients/register", authMiddleware(http.HandlerFunc(agencyHandler.RegisterClient))).Methods("POST")
|
||||
|
||||
@@ -190,6 +234,63 @@ func main() {
|
||||
router.Handle("/api/companies", authMiddleware(http.HandlerFunc(companyHandler.List))).Methods("GET")
|
||||
router.Handle("/api/companies/create", authMiddleware(http.HandlerFunc(companyHandler.Create))).Methods("POST")
|
||||
|
||||
// ==================== CRM ROUTES (TENANT) ====================
|
||||
|
||||
// Tenant solutions (which solutions the tenant has access to)
|
||||
router.Handle("/api/tenant/solutions", authMiddleware(http.HandlerFunc(solutionHandler.GetTenantSolutions))).Methods("GET")
|
||||
|
||||
// Customers
|
||||
router.Handle("/api/crm/customers", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetCustomers(w, r)
|
||||
case http.MethodPost:
|
||||
crmHandler.CreateCustomer(w, r)
|
||||
}
|
||||
}))).Methods("GET", "POST")
|
||||
|
||||
router.Handle("/api/crm/customers/{id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetCustomer(w, r)
|
||||
case http.MethodPut, http.MethodPatch:
|
||||
crmHandler.UpdateCustomer(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.DeleteCustomer(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT", "PATCH", "DELETE")
|
||||
|
||||
// Lists
|
||||
router.Handle("/api/crm/lists", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetLists(w, r)
|
||||
case http.MethodPost:
|
||||
crmHandler.CreateList(w, r)
|
||||
}
|
||||
}))).Methods("GET", "POST")
|
||||
|
||||
router.Handle("/api/crm/lists/{id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
crmHandler.GetList(w, r)
|
||||
case http.MethodPut, http.MethodPatch:
|
||||
crmHandler.UpdateList(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.DeleteList(w, r)
|
||||
}
|
||||
}))).Methods("GET", "PUT", "PATCH", "DELETE")
|
||||
|
||||
// Customer <-> List relationship
|
||||
router.Handle("/api/crm/customers/{customer_id}/lists/{list_id}", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPost:
|
||||
crmHandler.AddCustomerToList(w, r)
|
||||
case http.MethodDelete:
|
||||
crmHandler.RemoveCustomerFromList(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