feat: Add charging routes and handler integration to API server

- Add chargingH field to serverDeps struct
- Add ChargingEngineClient initialization in buildDeps
- Add NewChargingHandler with chargingEngineClient dependency
- Add registerChargingRoutes function with /charging group
- Add POST /charging/credit/:ip/check endpoint
- Add GET /charging/credit/:ip/balance endpoint
- Add POST /charging/credit/:ip/add endpoint
- Add POST /charging/credit/:ip/deduct endpoint
- Call registerChargingRoutes in
This commit is contained in:
nutcas3
2026-04-25 03:32:05 +03:00
parent 6d0c0ced1b
commit 7aa582ee3d
2 changed files with 14 additions and 0 deletions
+5
View File
@@ -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),
}
}
+9
View File
@@ -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)
}