Skip to content

Commit 3056a09

Browse files
add di to the routers
1 parent 16bce98 commit 3056a09

5 files changed

Lines changed: 19 additions & 82 deletions

File tree

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_application() -> FastAPI:
5656

5757
# Initialize the main application container
5858
main_container = ApplicationStartupContainer()
59-
main_container.wire(modules=["app.main"])
59+
main_container.wire(modules=["app.main", "app.presentation.api.botx"])
6060

6161
# Initialize the SampleRecord commands container
6262
sample_record_commands_container = BotSampleRecordCommandContainer()

app/presentation/api/bot.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/presentation/api/botx.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Endpoints for communication with botx."""
22

33
from http import HTTPStatus
4-
5-
from fastapi import APIRouter, Request
4+
from dependency_injector.wiring import inject, Provide
5+
from fastapi import APIRouter, Request, Depends
66
from fastapi.responses import JSONResponse
77
from pybotx import (
88
Bot,
@@ -16,15 +16,19 @@
1616
)
1717
from pybotx.constants import BOT_API_VERSION
1818

19+
from app.infrastructure.containers import ApplicationStartupContainer
1920
from app.logger import logger
20-
from app.presentation.api.bot import bot_dependency
2121
from app.settings import settings
2222

2323
router = APIRouter()
2424

2525

2626
@router.post("/command")
27-
async def command_handler(request: Request, bot: Bot = bot_dependency) -> JSONResponse:
27+
@inject
28+
async def command_handler(
29+
request: Request,
30+
bot: Bot = Depends(Provide[ApplicationStartupContainer.bot]),
31+
) -> JSONResponse:
2832
"""Receive commands from users. Max timeout - 5 seconds."""
2933

3034
try:
@@ -78,7 +82,11 @@ async def command_handler(request: Request, bot: Bot = bot_dependency) -> JSONRe
7882

7983

8084
@router.get("/status")
81-
async def status_handler(request: Request, bot: Bot = bot_dependency) -> JSONResponse:
85+
@inject
86+
async def status_handler(
87+
request: Request,
88+
bot: Bot = Depends(Provide[ApplicationStartupContainer.bot]),
89+
) -> JSONResponse:
8290
"""Show bot status and commands list."""
8391

8492
try:
@@ -112,7 +120,11 @@ async def status_handler(request: Request, bot: Bot = bot_dependency) -> JSONRes
112120

113121

114122
@router.post("/notification/callback")
115-
async def callback_handler(request: Request, bot: Bot = bot_dependency) -> JSONResponse:
123+
@inject
124+
async def callback_handler(
125+
request: Request,
126+
bot: Bot = Depends(Provide[ApplicationStartupContainer.bot]),
127+
) -> JSONResponse:
116128
"""Process BotX methods callbacks."""
117129

118130
try:

app/presentation/dependencies/__init__.py

Whitespace-only changes.

app/presentation/dependencies/healthcheck.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)