mirror of
https://github.com/wowlikon/LiB.git
synced 2026-02-04 04:31:09 +00:00
67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
"""Модуль настроек проекта"""
|
||
import os
|
||
|
||
from dotenv import load_dotenv
|
||
from fastapi import FastAPI
|
||
from sqlmodel import Session, create_engine
|
||
from toml import load
|
||
|
||
load_dotenv()
|
||
|
||
with open("pyproject.toml", 'r', encoding='utf-8') as f:
|
||
config = load(f)
|
||
|
||
|
||
def get_app() -> FastAPI:
|
||
"""Dependency, для получение экземплярра FastAPI application"""
|
||
return FastAPI(
|
||
title=config["tool"]["poetry"]["name"],
|
||
description=config["tool"]["poetry"]["description"],
|
||
version=config["tool"]["poetry"]["version"],
|
||
openapi_tags=[
|
||
{
|
||
"name": "authentication",
|
||
"description": "Авторизация пользователя."
|
||
},
|
||
{
|
||
"name": "authors",
|
||
"description": "Действия с авторами.",
|
||
},
|
||
{
|
||
"name": "books",
|
||
"description": "Действия с книгами.",
|
||
},
|
||
{
|
||
"name": "genres",
|
||
"description": "Действия с жанрами.",
|
||
},
|
||
{
|
||
"name": "relations",
|
||
"description": "Действия с связями.",
|
||
},
|
||
{
|
||
"name": "misc",
|
||
"description": "Прочие.",
|
||
},
|
||
],
|
||
)
|
||
|
||
|
||
HOST = os.getenv("POSTGRES_HOST")
|
||
PORT = os.getenv("POSTGRES_PORT")
|
||
USER = os.getenv("POSTGRES_USER")
|
||
PASSWORD = os.getenv("POSTGRES_PASSWORD")
|
||
DATABASE = os.getenv("POSTGRES_DB")
|
||
|
||
if not USER or not PASSWORD or not DATABASE or not HOST:
|
||
raise ValueError("Missing environment variables")
|
||
|
||
POSTGRES_DATABASE_URL = f"postgresql://{USER}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}"
|
||
engine = create_engine(POSTGRES_DATABASE_URL, echo=True, future=True)
|
||
|
||
|
||
def get_session():
|
||
"""Dependency, для получение сессии БД"""
|
||
with Session(engine) as session:
|
||
yield session
|