38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
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)
|