fix(erp): enable erp pages and menu items

This commit is contained in:
Erik Silva
2025-12-29 17:23:59 -03:00
parent e124a64a5d
commit adbff9bb1e
13990 changed files with 1110936 additions and 59 deletions

View File

@@ -60,6 +60,8 @@ func main() {
subscriptionRepo := repository.NewSubscriptionRepository(db)
crmRepo := repository.NewCRMRepository(db)
solutionRepo := repository.NewSolutionRepository(db)
erpRepo := repository.NewERPRepository(db)
docRepo := repository.NewDocumentRepository(db)
// Initialize services
authService := service.NewAuthService(userRepo, tenantRepo, crmRepo, cfg)
@@ -83,6 +85,8 @@ func main() {
agencyTemplateHandler := handlers.NewAgencyTemplateHandler(agencyTemplateRepo, agencyService, userRepo, tenantRepo)
filesHandler := handlers.NewFilesHandler(cfg)
customerPortalHandler := handlers.NewCustomerPortalHandler(crmRepo, authService, cfg)
erpHandler := handlers.NewERPHandler(erpRepo)
docHandler := handlers.NewDocumentHandler(docRepo)
// Initialize upload handler
uploadHandler, err := handlers.NewUploadHandler(cfg)
@@ -424,6 +428,133 @@ func main() {
}
}))).Methods("POST", "DELETE")
// ==================== ERP ROUTES (TENANT) ====================
// Finance
router.Handle("/api/erp/finance/categories", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
erpHandler.GetFinancialCategories(w, r)
case http.MethodPost:
erpHandler.CreateFinancialCategory(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/erp/finance/accounts", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
erpHandler.GetBankAccounts(w, r)
case http.MethodPost:
erpHandler.CreateBankAccount(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/erp/finance/accounts/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPut:
erpHandler.UpdateBankAccount(w, r)
case http.MethodDelete:
erpHandler.DeleteBankAccount(w, r)
}
}))).Methods("PUT", "DELETE")
router.Handle("/api/erp/finance/transactions", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
erpHandler.GetTransactions(w, r)
case http.MethodPost:
erpHandler.CreateTransaction(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/erp/finance/transactions/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPut:
erpHandler.UpdateTransaction(w, r)
case http.MethodDelete:
erpHandler.DeleteTransaction(w, r)
}
}))).Methods("PUT", "DELETE")
// Products
router.Handle("/api/erp/products", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
erpHandler.GetProducts(w, r)
case http.MethodPost:
erpHandler.CreateProduct(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/erp/products/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPut:
erpHandler.UpdateProduct(w, r)
case http.MethodDelete:
erpHandler.DeleteProduct(w, r)
}
}))).Methods("PUT", "DELETE")
// Orders
router.Handle("/api/erp/orders", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
erpHandler.GetOrders(w, r)
case http.MethodPost:
erpHandler.CreateOrder(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/erp/orders/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodDelete:
erpHandler.DeleteOrder(w, r)
}
}))).Methods("DELETE")
// Entities
router.Handle("/api/erp/entities", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
erpHandler.GetEntities(w, r)
case http.MethodPost:
erpHandler.CreateEntity(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/erp/entities/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPut, http.MethodPatch:
erpHandler.UpdateEntity(w, r)
case http.MethodDelete:
erpHandler.DeleteEntity(w, r)
}
}))).Methods("PUT", "PATCH", "DELETE")
// Documents
router.Handle("/api/documents", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
docHandler.List(w, r)
case http.MethodPost:
docHandler.Create(w, r)
}
}))).Methods("GET", "POST")
router.Handle("/api/documents/{id}", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
docHandler.Get(w, r)
case http.MethodPut:
docHandler.Update(w, r)
case http.MethodDelete:
docHandler.Delete(w, r)
}
}))).Methods("GET", "PUT", "DELETE")
router.Handle("/api/documents/{id}/subpages", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(docHandler.GetSubpages))).Methods("GET")
router.Handle("/api/documents/{id}/activities", middleware.RequireAgencyUser(cfg)(http.HandlerFunc(docHandler.GetActivities))).Methods("GET")
// Apply global middlewares: tenant -> cors -> security -> rateLimit -> router
handler := tenantDetector(corsMiddleware(securityMiddleware(rateLimitMiddleware(router))))