Files
vpn-control-panel/app/repositories/tariff.py
smolkik-code 7c7c88621d Initial commit: VPN Control Panel
- FastAPI REST API with JWT auth
- aiogram 3 Telegram bot with admin middleware
- APScheduler daily tasks (expiry, reminders, revoke, sync)
- SQLAlchemy 2 async ORM with Alembic migrations
- Jinja2 admin panel (Dashboard, Users, Payments, Servers, Tariffs)
- VPN provider abstraction with MockProvider
- Stats service with revenue/subscription analytics
- Docker Compose (PostgreSQL + Redis + app)
- Healthcheck endpoint
2026-07-05 17:50:11 +07:00

47 lines
1.5 KiB
Python

from sqlalchemy import select
from app.models.tariff import Tariff
from app.repositories.base import BaseRepository
class TariffRepository(BaseRepository[Tariff]):
def __init__(self, session):
super().__init__(session, Tariff)
async def get_active_tariffs(self) -> list[Tariff]:
stmt = (
select(Tariff)
.where(Tariff.is_active.is_(True))
.order_by(Tariff.price.asc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_by_name(self, name: str) -> Tariff | None:
stmt = select(Tariff).where(Tariff.name == name)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def get_by_price_range(
self, min_price: float, max_price: float
) -> list[Tariff]:
stmt = (
select(Tariff)
.where(Tariff.price >= min_price)
.where(Tariff.price <= max_price)
.where(Tariff.is_active.is_(True))
.order_by(Tariff.price.asc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_cheapest(self) -> Tariff | None:
stmt = (
select(Tariff)
.where(Tariff.is_active.is_(True))
.order_by(Tariff.price.asc())
.limit(1)
)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()