feat: /internal/renewal/pending
This commit is contained in:
@@ -2,6 +2,7 @@ from fastapi import APIRouter
|
||||
|
||||
from .auth import router as auth_router
|
||||
from .health import router as health_router
|
||||
from .internal import internal_router
|
||||
from .link_codes import router as link_code_router
|
||||
from .orders import router as orders_router
|
||||
from .payments import payment_router
|
||||
@@ -16,4 +17,5 @@ routers: list[APIRouter] = [
|
||||
health_router,
|
||||
link_code_router,
|
||||
payment_router,
|
||||
internal_router,
|
||||
]
|
||||
|
||||
6
routes/internal/__init__.py
Normal file
6
routes/internal/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .renewal import router as renewal_router
|
||||
|
||||
internal_router = APIRouter(prefix="/internal")
|
||||
internal_router.include_router(renewal_router)
|
||||
37
routes/internal/renewal.py
Normal file
37
routes/internal/renewal.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from core.deps import get_service_identity
|
||||
from db.session import get_db
|
||||
from repositories.service_notifications import (
|
||||
get_pending_notifications,
|
||||
mark_notification_as_dispatched,
|
||||
)
|
||||
from schemas.dto import ServiceIdentity
|
||||
from schemas.notifications import NotificationResponse, UserNotificationData
|
||||
|
||||
router = APIRouter(prefix="/renewal")
|
||||
|
||||
|
||||
@router.get("/pending", response_model=NotificationResponse)
|
||||
async def get_pending(
|
||||
limit: int = 50,
|
||||
ctx: ServiceIdentity = Depends(get_service_identity),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
):
|
||||
notifications = await get_pending_notifications(session, limit)
|
||||
|
||||
response_users: list[UserNotificationData] = []
|
||||
for notification in notifications:
|
||||
response_users.append(
|
||||
UserNotificationData(
|
||||
username=notification.subscription.user.username,
|
||||
telegram_id=notification.subscription.user.telegram_id,
|
||||
expires_at=notification.sub_expires_at,
|
||||
notification_type=notification.notify_type,
|
||||
)
|
||||
)
|
||||
|
||||
await mark_notification_as_dispatched(session, notification.id)
|
||||
|
||||
return NotificationResponse(users=response_users, issued_by=ctx.service)
|
||||
Reference in New Issue
Block a user