- Implemented SubscriptionRepository with methods to get, create, and update subscriptions. - Added BalanceTXRepository for creating and retrieving balance transactions. - Introduced a test script for simulating Pally webhook for local testing.
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from sqlalchemy import select, update
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from db.models.bills import Bill, DepositStatus
|
|
|
|
|
|
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: DepositStatus | None = DepositStatus.PENDING,
|
|
) -> Bill:
|
|
bill = Bill(creator_id=creator_id, amount=amount, status=status)
|
|
session.add(bill)
|
|
await session.commit()
|
|
return bill
|
|
|
|
async def update_bill_status(self, session: AsyncSession, bill_id: int, status: DepositStatus):
|
|
stmt = update(Bill).where(Bill.id == bill_id).values(status=status).returning(Bill)
|
|
result = await session.execute(stmt)
|
|
await session.commit()
|
|
return result.scalar_one_or_none()
|