feat(orders): integrate Pally payment and order management
This commit is contained in:
34
repositories/invoices.py
Normal file
34
repositories/invoices.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models.invoice import Invoice
|
||||
from schemas.invoices import InvoiceStatus
|
||||
|
||||
|
||||
class InvoiceRepository:
|
||||
def __init__(self, session: AsyncSession) -> None:
|
||||
self.session = session
|
||||
|
||||
async def get_by_id(self, id: int) -> Invoice | None:
|
||||
stmt = select(Invoice).where(Invoice.id == id)
|
||||
r = await self.session.execute(stmt)
|
||||
|
||||
return r.scalar_one_or_none()
|
||||
|
||||
async def get_by_user_id(self, user_id: int) -> list[Invoice]:
|
||||
stmt = select(Invoice).where(Invoice.creator_id == user_id)
|
||||
r = await self.session.execute(stmt)
|
||||
|
||||
return list(r.scalars().all())
|
||||
|
||||
async def create(self, creator_id: int, amount: int | float, status: InvoiceStatus) -> Invoice:
|
||||
obj = Invoice(
|
||||
creator_id=creator_id,
|
||||
amount=amount,
|
||||
status=status,
|
||||
)
|
||||
|
||||
self.session.add(obj)
|
||||
await self.session.commit()
|
||||
|
||||
return obj
|
||||
Reference in New Issue
Block a user