fix!: removed .commit() from repository level
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
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 db.session import UnitOfWork, get_uow
|
||||
from repositories.service_notifications import (
|
||||
ack_notification,
|
||||
get_pending_notifications,
|
||||
@@ -22,9 +21,9 @@ router = APIRouter(prefix="/renewal")
|
||||
async def get_pending(
|
||||
limit: int = 50,
|
||||
ctx: ServiceIdentity = Depends(get_service_identity),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
uow: UnitOfWork = Depends(get_uow),
|
||||
):
|
||||
notifications = await get_pending_notifications(session, limit)
|
||||
notifications = await get_pending_notifications(uow, limit)
|
||||
|
||||
response_users: list[UserNotificationData] = []
|
||||
for notification in notifications:
|
||||
@@ -38,8 +37,9 @@ async def get_pending(
|
||||
)
|
||||
)
|
||||
|
||||
await mark_notification_as_dispatched(session, notification.id)
|
||||
await mark_notification_as_dispatched(uow, notification.id)
|
||||
|
||||
await uow.commit()
|
||||
return NotificationResponse(users=response_users, issued_by=ctx.service)
|
||||
|
||||
|
||||
@@ -47,13 +47,14 @@ async def get_pending(
|
||||
async def acknowledge(
|
||||
req: NotificationAcknowledgeRequest,
|
||||
ctx: ServiceIdentity = Depends(get_service_identity),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
uow: UnitOfWork = Depends(get_uow),
|
||||
):
|
||||
try:
|
||||
r = await ack_notification(session, req.notification_id)
|
||||
r = await ack_notification(uow, req.notification_id)
|
||||
except Exception as e:
|
||||
raise HTTPException(500, detail=str(e)) from None
|
||||
|
||||
if r:
|
||||
await uow.commit()
|
||||
return "OK"
|
||||
raise HTTPException(500, detail="No such notification found.")
|
||||
|
||||
Reference in New Issue
Block a user