7971d3f76a
Agent-Logs-Url: https://github.com/christianlouis/pop_puller_to_gmail/sessions/98c1f90b-0287-4908-a0be-ad066c453cc5 Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Subscription and payment endpoints"""
|
|
|
|
from typing import List
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select
|
|
|
|
from app.core.database import get_db
|
|
from app.core.deps import get_current_active_user
|
|
from app.models.database_models import User, SubscriptionPlan
|
|
from app.models.schemas import SubscriptionPlanResponse
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/plans", response_model=List[SubscriptionPlanResponse])
|
|
async def list_subscription_plans(db: AsyncSession = Depends(get_db)):
|
|
"""List all available subscription plans"""
|
|
result = await db.execute(
|
|
select(SubscriptionPlan).where(SubscriptionPlan.is_active == True) # noqa: E712
|
|
)
|
|
return result.scalars().all()
|
|
|
|
|
|
@router.get("/current")
|
|
async def get_current_subscription(
|
|
current_user: User = Depends(get_current_active_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
"""Get current user's subscription details including plan limits"""
|
|
plan_result = await db.execute(
|
|
select(SubscriptionPlan).where(
|
|
SubscriptionPlan.tier == current_user.subscription_tier,
|
|
SubscriptionPlan.is_active.is_(True),
|
|
)
|
|
)
|
|
plan = plan_result.scalar_one_or_none()
|
|
|
|
return {
|
|
"tier": current_user.subscription_tier,
|
|
"status": current_user.subscription_status,
|
|
"expires_at": current_user.subscription_expires_at,
|
|
"max_mail_accounts": plan.max_mail_accounts if plan else None,
|
|
"max_emails_per_day": plan.max_emails_per_day if plan else None,
|
|
"check_interval_minutes": plan.check_interval_minutes if plan else None,
|
|
}
|