feat: Add tenant context injection to currency service methods for downstream isolation

- Replace TODO comments with context.WithValue calls injecting tenant_id in ProcessBilling
- Add tenant context injection in ConvertAmount for tenant-specific exchange rates
- Add tenant context injection in GetBillingHistory for repository-level filtering
- Add tenant context injection in CalculateTotalBilling for scoped calculations
- Update comments to reflect context-based isolation strategy
This commit is contained in:
nutcas3
2026-05-02 17:54:22 +03:00
parent 31fefa643f
commit 76052466e1
@@ -28,9 +28,8 @@ func (tacs *TenantAwareCurrencyService) ProcessBilling(ctx context.Context, req
"currency": req.Currency, "currency": req.Currency,
}).Info("Processing tenant billing request") }).Info("Processing tenant billing request")
// In a real implementation, this would ensure the billing operation // Inject tenant ID into context for downstream isolation
// is isolated to the specific tenant. For now, delegate to the underlying service ctx = context.WithValue(ctx, "tenant_id", tacs.tenantID)
// with proper logging for audit purposes.
return tacs.billingService.ProcessBilling(ctx, req) return tacs.billingService.ProcessBilling(ctx, req)
} }
@@ -44,8 +43,8 @@ func (tacs *TenantAwareCurrencyService) ConvertAmount(ctx context.Context, req *
"amount": req.Amount, "amount": req.Amount,
}).Info("Processing tenant currency conversion") }).Info("Processing tenant currency conversion")
// In a real implementation, this would ensure the conversion operation // Inject tenant ID into context for downstream isolation
// is isolated to the specific tenant and use tenant-specific exchange rates ctx = context.WithValue(ctx, "tenant_id", tacs.tenantID)
return tacs.billingService.ConvertAmount(ctx, req) return tacs.billingService.ConvertAmount(ctx, req)
} }
@@ -56,9 +55,8 @@ func (tacs *TenantAwareCurrencyService) GetBillingHistory(ctx context.Context, p
"tenant_id": tacs.tenantID, "tenant_id": tacs.tenantID,
"profile_id": profileID, "profile_id": profileID,
}).Info("Retrieving tenant billing history") }).Info("Retrieving tenant billing history")
// In a real implementation, this would filter results to only include // Inject tenant ID into context so the repository layer filters by tenant
// transactions belonging to the specific tenant ctx = context.WithValue(ctx, "tenant_id", tacs.tenantID)
return tacs.billingService.GetBillingHistory(ctx, profileID, filter) return tacs.billingService.GetBillingHistory(ctx, profileID, filter)
} }
@@ -72,8 +70,8 @@ func (tacs *TenantAwareCurrencyService) CalculateTotalBilling(ctx context.Contex
"to_date": toDate, "to_date": toDate,
}).Info("Calculating tenant total billing") }).Info("Calculating tenant total billing")
// In a real implementation, this would filter by tenant // Inject tenant ID into context so the repository layer scopes calculations
// For now, delegate to the underlying service ctx = context.WithValue(ctx, "tenant_id", tacs.tenantID)
return tacs.billingService.CalculateTotalBilling(ctx, profileID, fromDate, toDate) return tacs.billingService.CalculateTotalBilling(ctx, profileID, fromDate, toDate)
} }