Skip to content

Commit c4a4dd6

Browse files
authored
feat: delete comments and add an env check
1 parent 23860a2 commit c4a4dd6

File tree

6 files changed

+24
-25
lines changed

6 files changed

+24
-25
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DEBUG=True
2+
3+
PROJECT_NAME="My app"
4+
VERSION="1.0.0"
5+
6+
DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/valory"

backend/app/crud/overlay.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
from sqlalchemy.future import select
44

55
from app.models.overlay import Overlay
6-
# Импорты для моделей, схем и сессий
7-
from app.schemas.overlay import OverlaySchema, OverlayCreate # Pydantic-схема OverlayCreate
8-
from app.db.session import get_db # Асинхронная сессия базы данных
6+
from app.schemas.overlay import OverlaySchema, OverlayCreate
7+
from app.db.session import get_db
98

109
router = APIRouter()
1110

backend/app/db/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
22
from sqlalchemy.orm import sessionmaker
33
from sqlmodel import SQLModel
4+
from app import settings
45

5-
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/valory"
6-
engine = create_async_engine(DATABASE_URL, echo=True, future=True)
6+
engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)
77

88
AsyncSessionLocal = sessionmaker(
99
bind=engine,

backend/app/schemas/overlay.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ class OverlaySchema(BaseModel):
1111
tag: str
1212

1313
class Config:
14-
orm_mode = True # Включает поддержку ORM для SQLAlchemy моделей
14+
orm_mode = True
1515

1616
# Схема для создания записи
1717
class OverlayCreate(OverlayBase):
18-
pass # Наследует все поля от OverlayBase, используется для валидации входных данных
18+
pass
1919

20-
# Схема для ответа
2120
class OverlayRead(OverlayBase):
22-
uuid: uuid_pkg.UUID # Добавляем поле UUID в схему для ответа
21+
uuid: uuid_pkg.UUID
2322

2423
class Config:
25-
orm_mode = True # Поддержка работы с SQLAlchemy/SQLModel объектами
24+
orm_mode = True

backend/app/settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ def str_to_bool(value: str) -> bool:
88

99
BASE_DIR = Path(__file__).resolve().parent.parent.parent
1010

11-
print(BASE_DIR)
12-
1311
dotenv_file = BASE_DIR / '.env'
1412
if dotenv_file.is_file():
1513
load_dotenv(dotenv_file)
14+
else:
15+
raise ImportError('⚠ .env was not found')
16+
1617

1718
DEBUG = str_to_bool(environ.get("DEBUG", "False"))
1819

1920
PROJECT_NAME = environ.get('PROJECT_NAME')
20-
VERSION = environ.get('VERSION')
21+
VERSION = environ.get('VERSION')
22+
23+
DATABASE_URL = environ.get('DATABASE_URL')

backend/main.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,32 @@
66
from app import settings
77

88

9-
# Определение lifespan для управления событиями старта и завершения
109
@asynccontextmanager
1110
async def lifespan(app: FastAPI):
12-
# Выполняется при старте приложения
1311
await init_db()
14-
print("Application startup complete.")
12+
print("Application startup complete.")
1513

16-
yield # Передача управления основному приложению
14+
yield
1715

18-
# Выполняется при завершении приложения
19-
print("Application shutdown complete.")
16+
print("⚠ Application shutdown complete.")
2017

2118

22-
# Создание экземпляра FastAPI с lifespan
2319
app = FastAPI(
2420
title=settings.PROJECT_NAME,
2521
version=settings.VERSION,
2622
lifespan=lifespan
2723
)
2824

29-
# Подключение CORS middleware
3025
app.add_middleware(
3126
CORSMiddleware,
32-
allow_origins=["*"], # Замените "*" на список доменов в production
27+
allow_origins=["*"],
3328
allow_credentials=True,
3429
allow_methods=["*"],
3530
allow_headers=["*"],
3631
)
3732

38-
# Подключение роутов
3933
app.include_router(api_router, prefix="/api/v1")
4034

41-
42-
# Тестовый маршрут
4335
@app.get("/")
4436
async def read_root():
4537
return {"message": "Welcome to the API!"}

0 commit comments

Comments
 (0)