first commit
This commit is contained in:
0
app/notifications/__init__.py
Normal file
0
app/notifications/__init__.py
Normal file
16
app/notifications/models.py
Normal file
16
app/notifications/models.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database.base import Base
|
||||
|
||||
|
||||
class NotificationLog(Base):
|
||||
__tablename__ = "notification_logs"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
user_id: Mapped[int] = mapped_column(index=True)
|
||||
event_type: Mapped[str] = mapped_column(String(64), index=True)
|
||||
payload: Mapped[str] = mapped_column(String(1024))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
7
app/notifications/repository.py
Normal file
7
app/notifications/repository.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.notifications.models import NotificationLog
|
||||
|
||||
|
||||
async def create_notification_log(db: AsyncSession, *, user_id: int, event_type: str, payload: str) -> None:
|
||||
db.add(NotificationLog(user_id=user_id, event_type=event_type, payload=payload))
|
||||
3
app/notifications/router.py
Normal file
3
app/notifications/router.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/notifications", tags=["notifications"])
|
||||
7
app/notifications/schemas.py
Normal file
7
app/notifications/schemas.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class NotificationRequest(BaseModel):
|
||||
user_id: int
|
||||
event_type: str
|
||||
payload: dict
|
||||
13
app/notifications/service.py
Normal file
13
app/notifications/service.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.notifications.repository import create_notification_log
|
||||
from app.notifications.schemas import NotificationRequest
|
||||
|
||||
|
||||
async def enqueue_notification(db: AsyncSession, payload: NotificationRequest) -> None:
|
||||
await create_notification_log(
|
||||
db,
|
||||
user_id=payload.user_id,
|
||||
event_type=payload.event_type,
|
||||
payload=payload.payload.__repr__(),
|
||||
)
|
||||
Reference in New Issue
Block a user