34 lines
1020 B
Python
34 lines
1020 B
Python
from app.domain.models.answer_options import AnswerOption
|
|
|
|
|
|
class AnswerOptionsRepository:
|
|
def __init__(self, db):
|
|
self.db = db
|
|
|
|
def get_all(self):
|
|
return self.db.query(AnswerOption).all()
|
|
|
|
def get_by_id(self, answer_option_id: int):
|
|
return self.db.query(AnswerOption).filter(AnswerOption.id == answer_option_id).first()
|
|
|
|
def create(self, answer_option: AnswerOption):
|
|
self.db.add(answer_option)
|
|
self.db.commit()
|
|
self.db.refresh(answer_option)
|
|
return answer_option
|
|
|
|
def update(self, answer_option: AnswerOption):
|
|
self.db.merge(answer_option)
|
|
self.db.commit()
|
|
self.db.refresh(answer_option)
|
|
return answer_option
|
|
|
|
def delete(self, answer_option_id: int):
|
|
answer_option = self.db.query(AnswerOption).filter(AnswerOption.id == answer_option_id).first()
|
|
if answer_option:
|
|
self.db.delete(answer_option)
|
|
self.db.commit()
|
|
return answer_option
|
|
|
|
return None
|