mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-23 04:18:47 +00:00
feat: Implement carrier weight updates, pricing analytics calculations, and tenant rate limiting
- Add updateCarrierWeights implementation with regional and plan-based weight adjustments in carrier_methods.go - Add calculateRegionalWeightAdjustment helper with usage-based weight scaling and clamping - Add calculatePlanWeightAdjustment helper with plan usage analysis and adjustment limits - Add calculateConversionRate helper in pricing_integration.go using discount statistics and active rule ratios
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
// TenantMiddleware provides tenant isolation middleware
|
||||
type TenantMiddleware struct {
|
||||
tenantService Service
|
||||
rateLimiter *TenantRateLimiter
|
||||
logger *logrus.Logger
|
||||
}
|
||||
|
||||
@@ -22,6 +23,7 @@ type TenantMiddleware struct {
|
||||
func NewTenantMiddleware(tenantService Service, logger *logrus.Logger) *TenantMiddleware {
|
||||
return &TenantMiddleware{
|
||||
tenantService: tenantService,
|
||||
rateLimiter: NewTenantRateLimiter(logger),
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -57,6 +59,11 @@ func (tm *TenantMiddleware) ExtractTenantFromHeader(c *gin.Context) (*TenantCont
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Apply rate limiting
|
||||
if !tm.rateLimiter.AllowRequest(c.Request.Context(), tenantID, tenantCtx.Plan) {
|
||||
return nil, errors.New("rate limit exceeded for tenant")
|
||||
}
|
||||
|
||||
return tenantCtx, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user