some fix in docsyrings

main
Сергей Ванюшкин 2024-08-29 21:12:10 +00:00
parent 078d6d0c7a
commit 4ba1a31dee
8 changed files with 47 additions and 13 deletions

View File

@ -3,21 +3,27 @@ import logging
from fastapi import FastAPI from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker
from fastfood_two.app.depends.config import get_settings
from fastfood_two.app.depends.session import ( from fastfood_two.app.depends.session import (
create_engine, create_engine,
create_session_maker, create_session_maker,
get_session, get_session,
) )
from fastfood_two.common.logger import configure_logger from fastfood_two.common.logger import configure_logger
from fastfood_two.config import Config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
configure_logger(level=logging.INFO) configure_logger(level=logging.INFO)
def init_dependencies(app: FastAPI) -> None: def init_dependencies(app: FastAPI) -> None:
"""Initialize FastAPI dependencies.""" """Initialize FastAPI dependencies.
# app.dependency_overrides[Settings] = get_settings :param app: FastAPI application
:type app: FastAPI
"""
app.dependency_overrides[Config] = get_settings
app.dependency_overrides[AsyncEngine] = create_engine app.dependency_overrides[AsyncEngine] = create_engine
app.dependency_overrides[async_sessionmaker[AsyncSession]] = create_session_maker app.dependency_overrides[async_sessionmaker[AsyncSession]] = create_session_maker

View File

@ -0,0 +1,19 @@
import os
from functools import lru_cache
from fastfood_two.config import Config
from fastfood_two.storage.pg_storage.config import PostgresConfig
@lru_cache()
def get_settings() -> Config:
"""Возвращает настройки приложения"""
return Config(
db=PostgresConfig(
user=os.getenv("DB_USER", "test_user"),
password=os.getenv("DB_PASS", "test_password"),
host=os.getenv("DB_HOST", "localhost"),
port=int(os.getenv("DB_PORT", 5432)),
dbname=os.getenv("DB_NAME", "test_db"),
),
)

View File

@ -2,5 +2,9 @@ from fastapi import FastAPI
def init_errorhandlers(app: FastAPI) -> None: def init_errorhandlers(app: FastAPI) -> None:
"""Initialize FastAPI error handlers.""" """Initialize FastAPI error handlers.
:param app: FastAPI application
:type app: FastAPI
"""
pass pass

View File

@ -7,7 +7,11 @@ from fastfood_two.routers.summary import router as summary_router
def init_routers(app: FastAPI) -> None: def init_routers(app: FastAPI) -> None:
"""Initialize FastAPI routers.""" """Initialize FastAPI routers.
:param app: FastAPI application
:type app: FastAPI
"""
base_router = APIRouter( base_router = APIRouter(
prefix="/api/v1", prefix="/api/v1",
) )

View File

@ -2,7 +2,11 @@ import logging
def configure_logger(level=logging.INFO) -> None: def configure_logger(level=logging.INFO) -> None:
"""Configure the logger output string.""" """Configure the logger output string.
:param level: Logging level
:type level: int | logging.level INFO, WARNING, ERROR, CRITICAL, DEBUG
"""
logging.basicConfig( logging.basicConfig(
level=level, level=level,

View File

@ -7,8 +7,3 @@ class MenuResponse:
id: UUID id: UUID
name: str name: str
description: str description: str
@dataclass(frozen=True)
class MenusResponse:
menus: list[MenuResponse]

View File

View File

@ -1,8 +1,10 @@
from fastapi import APIRouter from fastapi import APIRouter
from fastfood_two.contracts.responses import MenuResponse
router = APIRouter(prefix="/menu", tags=["Menu"]) router = APIRouter(prefix="/menu", tags=["Menu"])
@router.get("/") @router.get("/", response_model=list[MenuResponse])
async def get_menus(): async def get_all_menus() -> list[MenuResponse]:
return return []