feat: advanced RW sync system

This commit is contained in:
2026-08-24 10:22:14 +07:00
parent b39cae8046
commit 8d1b753b99
12 changed files with 262 additions and 22 deletions

View File

@@ -1,14 +1,19 @@
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from core.deps import get_service_identity
from db.session import get_db
from repositories.service_notifications import (
ack_notification,
get_pending_notifications,
mark_notification_as_dispatched,
)
from schemas.dto import ServiceIdentity
from schemas.notifications import NotificationResponse, UserNotificationData
from schemas.notifications import (
NotificationAcknowledgeRequest,
NotificationResponse,
UserNotificationData,
)
router = APIRouter(prefix="/renewal")
@@ -25,6 +30,7 @@ async def get_pending(
for notification in notifications:
response_users.append(
UserNotificationData(
notification_id=notification.id,
username=notification.subscription.user.username,
telegram_id=notification.subscription.user.telegram_id,
expires_at=notification.sub_expires_at,
@@ -35,3 +41,19 @@ async def get_pending(
await mark_notification_as_dispatched(session, notification.id)
return NotificationResponse(users=response_users, issued_by=ctx.service)
@router.post("/ack")
async def acknowledge(
req: NotificationAcknowledgeRequest,
ctx: ServiceIdentity = Depends(get_service_identity),
session: AsyncSession = Depends(get_db),
):
try:
r = await ack_notification(session, req.notification_id)
except Exception as e:
raise HTTPException(500, detail=str(e)) from None
if r:
return "OK"
raise HTTPException(500, detail="No such notification found.")