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

68 lines
2.2 KiB
Python

from datetime import datetime
from sqlalchemy import select
from app.models.payment import Payment, PaymentStatus
from app.repositories.base import BaseRepository
class PaymentRepository(BaseRepository[Payment]):
def __init__(self, session):
super().__init__(session, Payment)
async def get_by_user_id(self, user_id: int) -> list[Payment]:
stmt = (
select(Payment)
.where(Payment.user_id == user_id)
.order_by(Payment.created_at.desc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_by_status(self, status: PaymentStatus) -> list[Payment]:
stmt = (
select(Payment)
.where(Payment.status == status)
.order_by(Payment.created_at.desc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_by_external_id(self, external_id: str) -> Payment | None:
stmt = select(Payment).where(Payment.external_id == external_id)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def get_by_date_range(
self, start: datetime, end: datetime
) -> list[Payment]:
stmt = (
select(Payment)
.where(Payment.created_at >= start)
.where(Payment.created_at <= end)
.order_by(Payment.created_at.desc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_pending_payments(self) -> list[Payment]:
stmt = (
select(Payment)
.where(Payment.status == PaymentStatus.PENDING)
.order_by(Payment.created_at.asc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
async def get_by_user_and_status(
self, user_id: int, status: PaymentStatus
) -> list[Payment]:
stmt = (
select(Payment)
.where(Payment.user_id == user_id)
.where(Payment.status == status)
.order_by(Payment.created_at.desc())
)
result = await self.session.execute(stmt)
return list(result.scalars().all())