feat(sub): handling upgrade/downgrade
rw integration and /me endpoints are left
This commit is contained in:
@@ -21,9 +21,12 @@ class InvoiceRepository:
|
||||
|
||||
return list(r.scalars().all())
|
||||
|
||||
async def create(self, creator_id: int, amount: int | float, status: InvoiceStatus) -> Invoice:
|
||||
async def create(
|
||||
self, creator_id: int, order_id: int, amount: int | float, status: InvoiceStatus
|
||||
) -> Invoice:
|
||||
obj = Invoice(
|
||||
creator_id=creator_id,
|
||||
order_id=order_id,
|
||||
amount=amount,
|
||||
status=status,
|
||||
)
|
||||
|
||||
@@ -10,9 +10,12 @@ class OrderRepository:
|
||||
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
user_id: int,
|
||||
devices: int,
|
||||
duration_days: int,
|
||||
total_amount: float,
|
||||
balance_amount: float,
|
||||
addons: list[str] | None = None,
|
||||
status: OrderStatus = OrderStatus.PENDING,
|
||||
) -> Order:
|
||||
@@ -23,6 +26,8 @@ class OrderRepository:
|
||||
user_id=user_id,
|
||||
devices=devices,
|
||||
duration_days=duration_days,
|
||||
total_amount=total_amount,
|
||||
balance_amount=balance_amount,
|
||||
status=status,
|
||||
)
|
||||
self.session.add(order)
|
||||
@@ -36,6 +41,12 @@ class OrderRepository:
|
||||
|
||||
return order
|
||||
|
||||
async def get_by_id(self, order_id: int) -> Order | None:
|
||||
stmt = select(Order).where(Order.id == order_id)
|
||||
r = await self.session.execute(stmt)
|
||||
|
||||
return r.scalar_one_or_none()
|
||||
|
||||
async def get_order_by_user_id(self, user_id: int) -> list[Order]:
|
||||
stmt = select(Order).where(Order.user_id == user_id)
|
||||
r = await self.session.execute(stmt)
|
||||
@@ -49,3 +60,15 @@ class OrderRepository:
|
||||
r = await self.session.execute(stmt)
|
||||
|
||||
return list(r.scalars().all())
|
||||
|
||||
async def get_paid_unapplied_by_user_id(self, user_id: int) -> list[Order]:
|
||||
stmt = (
|
||||
select(Order)
|
||||
.where(Order.user_id == user_id)
|
||||
.where(Order.status == OrderStatus.PAID)
|
||||
.where(Order.applied_at.is_(None))
|
||||
.order_by(Order.applies_at.asc(), Order.id.asc())
|
||||
)
|
||||
r = await self.session.execute(stmt)
|
||||
|
||||
return list(r.scalars().all())
|
||||
|
||||
Reference in New Issue
Block a user