feat: complete subscription billing system phases 6-10
Phase 6 - Database-driven tiers: - Update subscription_service to query database first with legacy fallback - Add get_tier_info() db parameter and _get_tier_from_legacy() method Phase 7 - Platform health integration: - Add get_subscription_capacity() for theoretical vs actual capacity - Include subscription capacity in full health report Phase 8 - Background subscription tasks: - Add reset_period_counters() for billing period resets - Add check_trial_expirations() for trial management - Add sync_stripe_status() for Stripe synchronization - Add cleanup_stale_subscriptions() for maintenance - Add capture_capacity_snapshot() for daily metrics Phase 10 - Capacity planning & forecasting: - Add CapacitySnapshot model for historical tracking - Create capacity_forecast_service with growth trends - Add /subscription-capacity, /trends, /recommendations endpoints - Add /snapshot endpoint for manual captures Also includes billing API enhancements from phase 4: - Add upcoming-invoice, change-tier, addon purchase/cancel endpoints - Add UsageSummary schema for billing page - Enhance billing.js with addon management functions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -144,3 +144,71 @@ async def get_capacity_metrics(
|
||||
"""Get capacity-focused metrics for planning."""
|
||||
metrics = platform_health_service.get_capacity_metrics(db)
|
||||
return CapacityMetricsResponse(**metrics)
|
||||
|
||||
|
||||
@router.get("/subscription-capacity")
|
||||
async def get_subscription_capacity(
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""
|
||||
Get subscription-based capacity metrics.
|
||||
|
||||
Shows theoretical vs actual capacity based on all vendor subscriptions.
|
||||
"""
|
||||
return platform_health_service.get_subscription_capacity(db)
|
||||
|
||||
|
||||
@router.get("/trends")
|
||||
async def get_growth_trends(
|
||||
days: int = 30,
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""
|
||||
Get growth trends over the specified period.
|
||||
|
||||
Returns growth rates and projections for key metrics.
|
||||
"""
|
||||
from app.services.capacity_forecast_service import capacity_forecast_service
|
||||
|
||||
return capacity_forecast_service.get_growth_trends(db, days=days)
|
||||
|
||||
|
||||
@router.get("/recommendations")
|
||||
async def get_scaling_recommendations(
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""
|
||||
Get scaling recommendations based on current capacity and growth.
|
||||
|
||||
Returns prioritized list of recommendations.
|
||||
"""
|
||||
from app.services.capacity_forecast_service import capacity_forecast_service
|
||||
|
||||
return capacity_forecast_service.get_scaling_recommendations(db)
|
||||
|
||||
|
||||
@router.post("/snapshot")
|
||||
async def capture_snapshot(
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""
|
||||
Manually capture a capacity snapshot.
|
||||
|
||||
Normally run automatically by daily background job.
|
||||
"""
|
||||
from app.services.capacity_forecast_service import capacity_forecast_service
|
||||
|
||||
snapshot = capacity_forecast_service.capture_daily_snapshot(db)
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"id": snapshot.id,
|
||||
"snapshot_date": snapshot.snapshot_date.isoformat(),
|
||||
"total_vendors": snapshot.total_vendors,
|
||||
"total_products": snapshot.total_products,
|
||||
"message": "Snapshot captured successfully",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user