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

36 lines
892 B
Python

from sqlalchemy.orm import Session
from app.domain.models.appeals import Appeal
class AppealsRepository:
def __init__(self, db: Session):
self.db = db
def get_all(self):
return self.db.query(Appeal).all()
def get_by_id(self, appeal_id: int):
return self.db.query(Appeal).filter(Appeal.id == appeal_id).first()
def create(self, appeal: Appeal):
self.db.add(appeal)
self.db.commit()
self.db.refresh(appeal)
return appeal
def update(self, appeal: Appeal):
self.db.merge(appeal)
self.db.commit()
self.db.refresh(appeal)
return appeal
def delete(self, appeal_id: int):
appeal = self.db.query(Appeal).filter(Appeal.id == appeal_id).first()
if appeal:
self.db.delete(appeal)
self.db.commit()
return appeal
return None