feat: /internal/renewal/pending

This commit is contained in:
2026-08-20 21:01:22 +07:00
parent 05ded7d7ea
commit 0a58a41930
10 changed files with 250 additions and 1 deletions

View 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)