2024-05-25 16:11:52 +04:00
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends
|
2024-06-02 16:38:08 +04:00
|
|
|
from typing import List
|
2024-05-25 16:11:52 +04:00
|
|
|
|
2024-06-02 16:38:08 +04:00
|
|
|
from enums import TypeMood, TypeModel
|
2024-05-25 16:51:34 +04:00
|
|
|
from repository import QuestionRepository
|
|
|
|
from schemas import SQuestionAdd, SQuestion, SQuestionId
|
2024-05-25 16:11:52 +04:00
|
|
|
|
|
|
|
router = APIRouter(
|
2024-05-25 16:51:34 +04:00
|
|
|
prefix="/questions",
|
|
|
|
tags=["Questions"],
|
2024-05-25 16:11:52 +04:00
|
|
|
)
|
|
|
|
|
2024-06-02 16:38:08 +04:00
|
|
|
@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
|
|
|
|
|
2024-05-25 16:11:52 +04:00
|
|
|
@router.post("")
|
2024-05-25 16:51:34 +04:00
|
|
|
async def add_question(
|
|
|
|
question: Annotated[SQuestionAdd, Depends()],
|
2024-06-02 16:38:08 +04:00
|
|
|
type_mood: TypeMood, # Добавлен параметр type_mood
|
|
|
|
type_model: TypeModel, # Добавлен параметр type_model
|
2024-05-25 16:51:34 +04:00
|
|
|
) -> SQuestionId:
|
2024-06-02 16:38:08 +04:00
|
|
|
question_id = await QuestionRepository.add_one(question, type_mood, type_model) # Передача параметров type_mood и type_model
|
2024-05-25 16:51:34 +04:00
|
|
|
return {"ok": True, "question_id": question_id}
|
2024-05-25 16:11:52 +04:00
|
|
|
|
|
|
|
@router.get("")
|
2024-05-25 16:51:34 +04:00
|
|
|
async def get_questions() -> list[SQuestion]:
|
|
|
|
questions = await QuestionRepository.find_all()
|
|
|
|
return questions
|
2024-06-02 16:38:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
@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
|