skill-forge/API/app/application/notifications_repository.py

36 lines
1.0 KiB
Python

from sqlalchemy.orm import Session
from app.domain.models.notifications import Notification
class NotificationsRepository:
def __init__(self, db: Session):
self.db = db
def get_all(self):
return self.db.query(Notification).all()
def get_by_id(self, notification_id: int):
return self.db.query(Notification).filter(Notification.id == notification_id).first()
def create(self, notification: Notification):
self.db.add(notification)
self.db.commit()
self.db.refresh(notification)
return notification
def update(self, notification: Notification):
self.db.merge(notification)
self.db.commit()
self.db.refresh(notification)
return notification
def delete(self, notification_id: int):
notification = self.db.query(Notification).filter(Notification.id == notification_id).first()
if notification:
self.db.delete(notification)
self.db.commit()
return notification
return None