diff --git a/apps/api-server/cmd/server_deps.go b/apps/api-server/cmd/server_deps.go index 0adacc6..a2f3d08 100644 --- a/apps/api-server/cmd/server_deps.go +++ b/apps/api-server/cmd/server_deps.go @@ -26,6 +26,7 @@ type serverDeps struct { configH *handlers.ConfigHandler chaosH *handlers.ChaosHandler billingH *handlers.BillingHandler + chargingH *handlers.ChargingHandler } // buildDeps constructs all downstream services and handlers. @@ -46,6 +47,9 @@ func buildDeps(db *database.Database, cfg *config.Config) *serverDeps { deploymentSvc := services.NewDeploymentService(db) promSvc := monitoring.NewPrometheusService() + // Initialize charging engine client + chargingEngineClient := services.NewChargingEngineClient(&cfg.ChargingEngine) + k8sSvc, k8sErr := services.NewKubernetesService() if k8sErr != nil { log.Printf("Kubernetes integration disabled: %v", k8sErr) @@ -63,6 +67,7 @@ func buildDeps(db *database.Database, cfg *config.Config) *serverDeps { configH: handlers.NewConfigHandler(configStoreSvc), chaosH: handlers.NewChaosHandler(chaosSvc), billingH: handlers.NewBillingHandler(invoiceSvc, db.DB), + chargingH: handlers.NewChargingHandler(chargingEngineClient), } } diff --git a/apps/api-server/cmd/server_routes.go b/apps/api-server/cmd/server_routes.go index 66dc4b1..d5c8667 100644 --- a/apps/api-server/cmd/server_routes.go +++ b/apps/api-server/cmd/server_routes.go @@ -51,6 +51,7 @@ func registerV1Routes(router *gin.Engine, d *serverDeps) { registerBillingRoutes(apiProtected, d) registerConfigRoutes(apiProtected, d) registerChaosRoutes(apiProtected, d) + registerChargingRoutes(apiProtected, d) } } @@ -159,3 +160,11 @@ func registerChaosRoutes(api *gin.RouterGroup, d *serverDeps) { applyRBAC(w, d.casbinSvc, "/v1/chaos", "POST", "admin") w.POST("/experiments", d.chaosH.Run) } + +func registerChargingRoutes(api *gin.RouterGroup, d *serverDeps) { + charging := api.Group("/charging") + charging.POST("/credit/:ip/check", d.chargingH.CheckCredit) + charging.GET("/credit/:ip/balance", d.chargingH.GetBalance) + charging.POST("/credit/:ip/add", d.chargingH.AddCredit) + charging.POST("/credit/:ip/deduct", d.chargingH.DeductCredit) +}