File size: 760 Bytes
26c9046 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | from __future__ import annotations
from datetime import datetime, timezone
from typing import Optional
from sqlalchemy.orm import Session
from models.notification import Notification
def create_notification(
db: Session,
*,
user_id: int,
title: str,
message: str,
kind: str = "info",
link_path: Optional[str] = None,
entity_type: Optional[str] = None,
entity_id: Optional[int] = None,
) -> Notification:
notification = Notification(
user_id=user_id,
kind=kind,
title=title,
message=message,
link_path=link_path,
entity_type=entity_type,
entity_id=entity_id,
)
db.add(notification)
db.commit()
db.refresh(notification)
return notification
|