feat: add subscription and transaction repositories
- 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.
This commit is contained in:
41
repositories/transactions.py
Normal file
41
repositories/transactions.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models.transactions import BalanceTransaction, BalanceTxType
|
||||
|
||||
|
||||
class BalanceTXRepository:
|
||||
async def create(
|
||||
self,
|
||||
session: AsyncSession,
|
||||
user_id: int,
|
||||
amount: int,
|
||||
tx_type: BalanceTxType,
|
||||
balance_before: int,
|
||||
balance_after: int,
|
||||
description: str,
|
||||
) -> BalanceTransaction:
|
||||
created_at = datetime.now(timezone.UTC)
|
||||
tx = BalanceTransaction(
|
||||
user_id=user_id,
|
||||
amount=amount,
|
||||
tx_type=tx_type,
|
||||
balance_before=balance_before,
|
||||
balance_after=balance_after,
|
||||
description=description,
|
||||
created_at=created_at,
|
||||
)
|
||||
session.add(tx)
|
||||
await session.commit()
|
||||
|
||||
return tx
|
||||
|
||||
async def get_transactions_by_id(
|
||||
self, session: AsyncSession, user_id: int, limit: int = 50
|
||||
) -> list[BalanceTransaction]:
|
||||
stmt = select(BalanceTransaction).where(BalanceTransaction.user_id == user_id).limit(limit)
|
||||
res = await session.execute(stmt)
|
||||
|
||||
return list(res.scalars().all())
|
||||
Reference in New Issue
Block a user