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

36 lines
1.0 KiB
Python

from sqlalchemy.orm import Session
from app.domain.models.appeals_topics import AppealsTopic
class AppealsTopicsRepository:
def __init__(self, db: Session):
self.db = db
def get_all(self):
return self.db.query(AppealsTopic).all()
def get_by_id(self, appeals_topic_id: int):
return self.db.query(AppealsTopic).filter(AppealsTopic.id == appeals_topic_id).first()
def create(self, appeals_topic: AppealsTopic):
self.db.add(appeals_topic)
self.db.commit()
self.db.refresh(appeals_topic)
return appeals_topic
def update(self, appeals_topic: AppealsTopic):
self.db.merge(appeals_topic)
self.db.commit()
self.db.refresh(appeals_topic)
return appeals_topic
def delete(self, appeals_topic_id: int):
appeals_topic = self.db.query(AppealsTopic).filter(AppealsTopic.id == appeals_topic_id).first()
if appeals_topic:
self.db.delete(appeals_topic)
self.db.commit()
return appeals_topic
return None