39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from typing import Optional, List
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.notification import Notification
|
|
from app.repositories.notification import NotificationRepository
|
|
|
|
|
|
class NotificationService:
|
|
def __init__(self, db: AsyncSession):
|
|
self.db = db
|
|
self.repo = NotificationRepository(db)
|
|
|
|
async def get_notifications(
|
|
self,
|
|
user_id: Optional[int] = None,
|
|
is_read: Optional[bool] = None,
|
|
type: Optional[str] = None,
|
|
page: int = 1,
|
|
page_size: int = 20
|
|
) -> List[Notification]:
|
|
return await self.repo.get_list(
|
|
user_id=user_id,
|
|
is_read=is_read,
|
|
type=type,
|
|
page=page,
|
|
page_size=page_size
|
|
)
|
|
|
|
async def create_notification(self, data: dict) -> Notification:
|
|
return await self.repo.create(data)
|
|
|
|
async def mark_as_read(self, notification_id: int) -> bool:
|
|
return await self.repo.mark_as_read(notification_id)
|
|
|
|
async def mark_all_as_read(self, user_id: int) -> int:
|
|
return await self.repo.mark_all_as_read(user_id)
|
|
|
|
async def delete_notification(self, notification_id: int) -> bool:
|
|
return await self.repo.delete(notification_id) |