PIbd-32_Kashin_M.I_API_Cour.../router.py

45 lines
1.6 KiB
Python

from typing import Annotated
from fastapi import APIRouter, Depends
from typing import List
from enums import TypeMood, TypeModel
from repository import QuestionRepository
from schemas import SQuestionAdd, SQuestion, SQuestionId
router = APIRouter(
prefix="/questions",
tags=["Questions"],
)
@router.get("/class_negative")
async def get_class_names() -> List[str]:
with open(".//neural_network/classification/class_names_negative.txt", "r", encoding="utf-8") as file:
class_names = [line.strip() for line in file.readlines()]
return class_names
@router.get("/class_positive")
async def get_class_names() -> List[str]:
with open(".//neural_network/classification/class_names_positive.txt", "r", encoding="utf-8") as file:
class_names = [line.strip() for line in file.readlines()]
return class_names
@router.post("")
async def add_question(
question: Annotated[SQuestionAdd, Depends()],
type_mood: TypeMood, # Добавлен параметр type_mood
type_model: TypeModel, # Добавлен параметр type_model
) -> SQuestionId:
question_id = await QuestionRepository.add_one(question, type_mood, type_model) # Передача параметров type_mood и type_model
return {"ok": True, "question_id": question_id}
@router.get("")
async def get_questions() -> list[SQuestion]:
questions = await QuestionRepository.find_all()
return questions
@router.get("/{email_user}")
async def get_questions_by_email(email_user: str) -> list[SQuestion]:
questions = await QuestionRepository.find_by_email(email_user)
return questions