init server

This commit is contained in:
Robin COuret
2026-02-10 17:36:30 +01:00
parent c9cb257afc
commit 83b5da1716
32 changed files with 238 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,13 @@
from src.questions.models import Question
from src.questions.crud import create_question as create_question_model, read_questions as read_questions_model, read_question as read_question_model
from src.knowledges.models import Knowledge
def create_question(knowledge: Knowledge):
question = Question(knowledge = knowledge, question = "Quel est le sens du mot connaissance ?")
create_question_model(question)
def read_questions(knowledge):
return read_questions_model(knowledge)
def read_question(question_id):
return read_question_model(question_id)

View File

@@ -0,0 +1,42 @@
from sqlmodel import Session, select
from src.questions.models import Question
from src.knowledges.models import Knowledge
from src.database import engine
def create_question(Question: Question):
with Session(engine) as session:
session.add(Question)
session.commit()
def read_questions(knowledge):
with Session(engine) as session:
statement = select(Question).where(Question.knowledge_id == knowledge.id)
results = session.exec(statement)
questions = results.all()
return questions
def read_question(question_id: int):
with Session(engine) as session:
question = session.get(Question, question_id)
return question
# #TODO adapt logic with args
# def update_question(question_id: int, content: str, uri: str):
# with Session(engine) as session:
# question = session.get(Question, question_id)
# question.content = content if content else question.content
# question.uri = uri if uri else question.uri
# session.add(question)
# session.commit()
# session.refresh(question)
#TODO : test
def delete_question(question_id: int):
with Session(engine) as session:
question = session.get(Question, question_id)
session.delete(question)
session.commit()

View File

@@ -0,0 +1,12 @@
from sqlmodel import Field, SQLModel, Relationship
from src.knowledges.models import Knowledge
#TODO : add pydantic validation
class Question(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
question:str
knowledge_id: int | None = Field(default=None, foreign_key="knowledge.id", ondelete="CASCADE")
knowledge: Knowledge | None = Relationship(back_populates="questions")
metrics: list["Metrics"] = Relationship(back_populates="question", cascade_delete=True) # type: ignore

View File

View File

View File