Files
vpn-control-panel/app/repositories/user.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

38 lines
1.2 KiB
Python

from datetime import datetime
from sqlalchemy import select
from app.models.user import User
from app.repositories.base import BaseRepository
class UserRepository(BaseRepository[User]):
def __init__(self, session):
super().__init__(session, User)
async def get_by_telegram_id(self, telegram_id: int) -> User | None:
stmt = select(User).where(User.telegram_id == telegram_id)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def get_active_users(self) -> list[User]:
stmt = select(User).where(User.is_active.is_(True))
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_by_username(self, username: str) -> list[User]:
stmt = select(User).where(User.username.ilike(username))
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_by_created_range(
self, start: datetime, end: datetime
) -> list[User]:
stmt = (
select(User)
.where(User.created_at >= start)
.where(User.created_at <= end)
)
result = await self.session.execute(stmt)
return list(result.scalars().all())