init server
This commit is contained in:
BIN
server/src/questions/__pycache__/controller.cpython-311.pyc
Normal file
BIN
server/src/questions/__pycache__/controller.cpython-311.pyc
Normal file
Binary file not shown.
BIN
server/src/questions/__pycache__/crud.cpython-311.pyc
Normal file
BIN
server/src/questions/__pycache__/crud.cpython-311.pyc
Normal file
Binary file not shown.
BIN
server/src/questions/__pycache__/models.cpython-311.pyc
Normal file
BIN
server/src/questions/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
13
server/src/questions/controller.py
Normal file
13
server/src/questions/controller.py
Normal 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)
|
||||
42
server/src/questions/crud.py
Normal file
42
server/src/questions/crud.py
Normal 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()
|
||||
|
||||
12
server/src/questions/models.py
Normal file
12
server/src/questions/models.py
Normal 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
|
||||
0
server/src/questions/router.py
Normal file
0
server/src/questions/router.py
Normal file
0
server/src/questions/service.py
Normal file
0
server/src/questions/service.py
Normal file
0
server/src/questions/utils.py
Normal file
0
server/src/questions/utils.py
Normal file
Reference in New Issue
Block a user