Раздробил роутер адекватно

This commit is contained in:
maksim 2024-06-02 17:33:50 +04:00
parent 10ee04f93f
commit 1e3a2f3efa
3 changed files with 29 additions and 13 deletions

View File

@ -3,7 +3,8 @@ import logging
from contextlib import asynccontextmanager
from database import create_tables, delete_tables
from router import router as questions_router
from router_questions import router as questions_router
from router_class import router as class_router
# Настройка логирования
logging.basicConfig(level=logging.INFO)
@ -20,3 +21,4 @@ async def lifespan(app: FastAPI):
app = FastAPI(lifespan=lifespan)
app.include_router(questions_router)
app.include_router(class_router)

25
router_class.py Normal file
View File

@ -0,0 +1,25 @@
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="/class",
tags=["Class"],
)
@router.get("/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("/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

View File

@ -11,18 +11,6 @@ router = APIRouter(
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()],
@ -42,3 +30,4 @@ async def get_questions() -> list[SQuestion]:
async def get_questions_by_email(email_user: str) -> list[SQuestion]:
questions = await QuestionRepository.find_by_email(email_user)
return questions