add KnowledgeWorkFlow system
This commit is contained in:
@@ -3,8 +3,10 @@ from fastapi import APIRouter
|
||||
from .knowledges import router as knowledge_router
|
||||
from .metrics import router as metric_router
|
||||
from .auth import router as auth_router
|
||||
from .questions import router as question_router
|
||||
|
||||
router = APIRouter(prefix="/v1")
|
||||
router.include_router(knowledge_router)
|
||||
router.include_router(question_router)
|
||||
router.include_router(metric_router)
|
||||
router.include_router(auth_router)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
server/src/app/api/v1/__pycache__/questions.cpython-311.pyc
Normal file
BIN
server/src/app/api/v1/__pycache__/questions.cpython-311.pyc
Normal file
Binary file not shown.
@@ -44,7 +44,7 @@ def generate_questions(id: int, current_user: Annotated[str, Depends(get_current
|
||||
)
|
||||
questions_raw = questions_generation(knowledge)
|
||||
for q in questions_raw:
|
||||
question = Question(question = q, knowledge=knowledge)
|
||||
question = Question(question = q, knowledge=knowledge, user=current_user)
|
||||
create_question(question)
|
||||
return questions_raw
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from src.app.auth.dependancies import get_current_user
|
||||
|
||||
router = APIRouter(tags=["metrics"])
|
||||
|
||||
@router.post("/metrics/")
|
||||
def create(metric_data: MetricCreate, current_user: Annotated[str, Depends(get_current_user)]):
|
||||
metric: Metric = Metric(question_id = metric_data.question_id, need_index = metric_data.need_index, user = current_user)
|
||||
created_metric: Metric = create_metric(metric)
|
||||
return created_metric
|
||||
# @router.post("/metrics/")
|
||||
# def create(metric_data: MetricCreate, current_user: Annotated[str, Depends(get_current_user)]):
|
||||
# metric: Metric = Metric(question_id = metric_data.question_id, need_index = metric_data.need_index, user = current_user)
|
||||
# created_metric: Metric = create_metric(metric)
|
||||
# return created_metric
|
||||
|
||||
38
server/src/app/api/v1/questions.py
Normal file
38
server/src/app/api/v1/questions.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from typing import Annotated
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from src.app.auth.dependancies import get_current_user
|
||||
|
||||
from src.app.models.question import Question
|
||||
from src.app.models.metric import Metric, MetricCreate
|
||||
|
||||
from src.app.data.question import get_question_by_id
|
||||
from src.app.data.metric import get_metrics, create_metric
|
||||
|
||||
#Added in __ini__
|
||||
router = APIRouter(tags=["questions"])
|
||||
|
||||
@router.get("/questions/{id}/metrics")
|
||||
def read_questions(id: int, current_user: Annotated[str, Depends(get_current_user)]):
|
||||
question: Question = get_question_by_id(id, current_user)
|
||||
if not question:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Forbidden. The requested knowledge is not available for the provided ID.",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
metrics = get_metrics(question)
|
||||
return metrics
|
||||
|
||||
@router.post("/questions/{id}/metrics")
|
||||
def create(id: int, metric_data: MetricCreate, current_user: Annotated[str, Depends(get_current_user)]):
|
||||
question: Question = get_question_by_id(id, current_user)
|
||||
if not question:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Forbidden. The requested knowledge is not available for the provided ID.",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
metric: Metric = Metric(question_id = id, need_index = metric_data.need_index, user = current_user)
|
||||
created_metric: Metric = create_metric(metric)
|
||||
return created_metric
|
||||
Binary file not shown.
@@ -1,13 +1,21 @@
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from src.app.models.question import Question
|
||||
from src.app.models.user import User
|
||||
from src.app.database import engine
|
||||
|
||||
def get_question_by_id(question_id: int):
|
||||
def get_question_by_id(question_id: int, user: User):
|
||||
with Session(engine) as session:
|
||||
question = session.get(Question, question_id)
|
||||
statement = select(Question).where(Question.id == question_id, Question.user_id == user.id)
|
||||
results = session.exec(statement)
|
||||
question = results.first()
|
||||
return question
|
||||
|
||||
# def get_question_by_id(question_id: int):
|
||||
# with Session(engine) as session:
|
||||
# question = session.get(Question, question_id)
|
||||
# return question
|
||||
|
||||
def get_questions(knowledge):
|
||||
with Session(engine) as session:
|
||||
statement = select(Question).where(Question.knowledge_id == knowledge.id)
|
||||
|
||||
Binary file not shown.
@@ -15,5 +15,4 @@ class Metric(SQLModel, table=True):
|
||||
user: User | None = Relationship(back_populates="metrics")
|
||||
|
||||
class MetricCreate(BaseModel):
|
||||
question_id: int
|
||||
need_index: int
|
||||
Reference in New Issue
Block a user