- Added billing models and repository for handling bills. - Introduced BillingService to manage payment initiation and bill creation. - Updated user service to remove ticket-related functionality. - Refactored settings to include new billing-related fields. - Removed ticket-related handlers and schemas. - Added new billing handlers for processing payments. - Updated database schema with new bills table and status enum. - Enhanced utility functions to calculate prices considering discounts. - Introduced prehandling for non-private messages. - Updated main application to initialize new billing services and repositories.
26 lines
716 B
Python
26 lines
716 B
Python
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from db.models.bills import Bill, BillStatus
|
|
|
|
|
|
class BillsRepository:
|
|
async def get_bill_by_id(self, session: AsyncSession, bill_id: int) -> Bill | None:
|
|
stmt = select(Bill).where(Bill.id == bill_id)
|
|
res = await session.execute(stmt)
|
|
|
|
return res.scalar_one_or_none()
|
|
|
|
async def create(
|
|
self,
|
|
session: AsyncSession,
|
|
*,
|
|
creator_id: int,
|
|
amount: int,
|
|
status: BillStatus | None = BillStatus.NEW,
|
|
) -> Bill:
|
|
bill = Bill(creator_id=creator_id, amount=amount, status=status)
|
|
session.add(bill)
|
|
await session.commit()
|
|
return bill
|