- Added notifications for successful payments in `api/core/notifications.py`. - Created main API entry point in `api/main.py` with FastAPI integration. - Established routing structure in `api/routes/__init__.py` and `api/routes/pally.py` for handling payment callbacks. - Developed billing handlers in `bot/handlers/billing.py` and `bot/handlers/buy.py` for subscription management. - Introduced state management for user interactions in `bot/states/`. - Created user interface elements in `bot/keyboards/` for navigation and payment processing. - Set up middleware for dependency injection in `bot/middlewares/di.py`. - Added support for user commands and interactions in `bot/handlers/common.py` and `bot/handlers/support.py`. - Implemented logging and error handling throughout the bot's functionality. - Created entry point script for API server in `entrypoints/api.sh`.
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
from collections.abc import AsyncGenerator
|
|
from contextlib import asynccontextmanager
|
|
|
|
from aiogram import Bot
|
|
from fastapi import FastAPI
|
|
|
|
from api.routes import routers
|
|
from config import settings
|
|
from repositories.bills import BillsRepository
|
|
from repositories.users import UserRepository
|
|
from schemas.di import APIDependenciesDTO
|
|
from services.billing_service import BillingService
|
|
from services.user_service import UserService
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator:
|
|
# Bot Init
|
|
bot = Bot(token=settings.bot_token)
|
|
app.state.bot = bot
|
|
|
|
user_repository = UserRepository()
|
|
user_service = UserService(user_repository)
|
|
|
|
bills_repository = BillsRepository()
|
|
bills_service = BillingService(
|
|
user_repository=user_repository, bills_repository=bills_repository
|
|
)
|
|
|
|
deps_dto = APIDependenciesDTO(
|
|
user_repository=user_repository,
|
|
user_service=user_service,
|
|
bills_repository=bills_repository,
|
|
billing_service=bills_service,
|
|
)
|
|
app.state.deps = deps_dto
|
|
|
|
for r in routers:
|
|
app.include_router(r)
|
|
|
|
yield # App's lifespan
|
|
|
|
await bot.session.close() # D IE!!!!!!!!
|
|
|
|
|
|
app = FastAPI(
|
|
title="Malenia API",
|
|
description="Payment webhook handler and user balance management",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
docs_url="",
|
|
)
|