diff --git a/src/fastfood_two/app/dependencies.py b/src/fastfood_two/app/dependencies.py index 6dcb3c5..bc2088a 100644 --- a/src/fastfood_two/app/dependencies.py +++ b/src/fastfood_two/app/dependencies.py @@ -3,21 +3,27 @@ import logging from fastapi import FastAPI 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 ( create_engine, create_session_maker, get_session, ) from fastfood_two.common.logger import configure_logger +from fastfood_two.config import Config logger = logging.getLogger(__name__) configure_logger(level=logging.INFO) 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[async_sessionmaker[AsyncSession]] = create_session_maker diff --git a/src/fastfood_two/app/depends/config.py b/src/fastfood_two/app/depends/config.py new file mode 100644 index 0000000..ca21736 --- /dev/null +++ b/src/fastfood_two/app/depends/config.py @@ -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"), + ), + ) diff --git a/src/fastfood_two/app/error_handlers.py b/src/fastfood_two/app/error_handlers.py index dd3a370..123c686 100644 --- a/src/fastfood_two/app/error_handlers.py +++ b/src/fastfood_two/app/error_handlers.py @@ -2,5 +2,9 @@ from fastapi import FastAPI def init_errorhandlers(app: FastAPI) -> None: - """Initialize FastAPI error handlers.""" + """Initialize FastAPI error handlers. + + :param app: FastAPI application + :type app: FastAPI + """ pass diff --git a/src/fastfood_two/app/routers.py b/src/fastfood_two/app/routers.py index 33f94f3..d9620d7 100644 --- a/src/fastfood_two/app/routers.py +++ b/src/fastfood_two/app/routers.py @@ -7,7 +7,11 @@ from fastfood_two.routers.summary import router as summary_router def init_routers(app: FastAPI) -> None: - """Initialize FastAPI routers.""" + """Initialize FastAPI routers. + + :param app: FastAPI application + :type app: FastAPI + """ base_router = APIRouter( prefix="/api/v1", ) diff --git a/src/fastfood_two/common/logger.py b/src/fastfood_two/common/logger.py index 8343b5c..5eb5085 100644 --- a/src/fastfood_two/common/logger.py +++ b/src/fastfood_two/common/logger.py @@ -2,7 +2,11 @@ import logging 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( level=level, diff --git a/src/fastfood_two/contracts/menu_contracts.py b/src/fastfood_two/contracts/responses.py similarity index 66% rename from src/fastfood_two/contracts/menu_contracts.py rename to src/fastfood_two/contracts/responses.py index ae3a6fc..0e32a5f 100644 --- a/src/fastfood_two/contracts/menu_contracts.py +++ b/src/fastfood_two/contracts/responses.py @@ -7,8 +7,3 @@ class MenuResponse: id: UUID name: str description: str - - -@dataclass(frozen=True) -class MenusResponse: - menus: list[MenuResponse] diff --git a/src/fastfood_two/contracts/usecases.py b/src/fastfood_two/contracts/usecases.py new file mode 100644 index 0000000..e69de29 diff --git a/src/fastfood_two/routers/menu.py b/src/fastfood_two/routers/menu.py index d0c46d5..4a08f79 100644 --- a/src/fastfood_two/routers/menu.py +++ b/src/fastfood_two/routers/menu.py @@ -1,8 +1,10 @@ from fastapi import APIRouter +from fastfood_two.contracts.responses import MenuResponse + router = APIRouter(prefix="/menu", tags=["Menu"]) -@router.get("/") -async def get_menus(): - return +@router.get("/", response_model=list[MenuResponse]) +async def get_all_menus() -> list[MenuResponse]: + return []