50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from src.cache.redis_client import redis_client
|
|
from src.database.users.crud import Seed
|
|
from src.logging.logger import LoggingMiddleware, ProcessingTimeMiddleware
|
|
from src.messaging.rabbitmq_client import rabbitmq_client
|
|
from src.web.protected_routes.auth_routes import router as protected_router
|
|
from src.web.protected_routes.protected_user_action_routes import (
|
|
router as protected_user_action_routes,
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
create_dirs()
|
|
await create_first_user()
|
|
yield
|
|
await redis_client.close()
|
|
await rabbitmq_client.close()
|
|
|
|
app=FastAPI(root_path="/", lifespan=lifespan)
|
|
app.add_middleware(LoggingMiddleware)
|
|
app.add_middleware(ProcessingTimeMiddleware)
|
|
app.include_router(router=protected_router)
|
|
app.include_router(router=protected_user_action_routes)
|
|
|
|
|
|
@app.get("")
|
|
async def root()->dict:
|
|
return {"root":"hello, this is root"}
|
|
|
|
|
|
def create_dirs()->None:
|
|
|
|
dirs_to_create=("./DB",
|
|
"./uploads/upload",
|
|
"./uploads/upload_bad",
|
|
"./uploads/upload_finished",
|
|
"./logs")
|
|
|
|
for x in dirs_to_create:
|
|
Path(x).mkdir(parents=True, exist_ok=True)
|
|
|
|
async def create_first_user()->None:
|
|
seed=Seed()
|
|
await seed.seed()
|
|
|